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