using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class PlusMinusCtrl : MonoBehaviour { public InputField NumberInput; public Button PlusBtn; public Button MinusBtn; private int number = 0; public int Number { get { return number; } set { this.number = value; NumberInput.text = number.ToString(); } } // Use this for initialization void Start() { PlusBtn.onClick.AddListener(Plus); NumberInput.onEndEdit.AddListener(InputNumber); MinusBtn.onClick.AddListener(Minus); } void Plus() { Number++; // NumberInput.text = Number.ToString(); } void Minus() { Number = --Number <= 1 ? 1 : Number; // NumberInput.text = Number.ToString(); } void InputNumber(string value) { Number = int.Parse(value); } }