using System.Collections; using System.Collections.Generic; using UnityEngine; public class script1 : MonoBehaviour { int a1, a2, a3; void Start() { //初始化 a1 = 0; a2 = 0; a3 = 0; } void OnGUI() { GUI.Box(new Rect(5, 5, 400, 200), "計算"); a1 = int.Parse(GUI.TextField(new Rect(5, 50, 75, 30),a1.ToString())); GUI.Label(new Rect(85, 50, 10, 30), "+"); a2 = int.Parse(GUI.TextField(new Rect(100, 50, 75, 30), a2.ToString())); GUI.Label(new Rect(185, 50, 10, 30), "="); GUI.TextField(new Rect(200, 50, 75, 30), a3.ToString()); if (GUI.Button(new Rect(70, 100, 100, 30), "加法")) { a3 = a1 + a2; } } }