using UnityEngine; using UnityEngine.UI; public sealed class CounterPanel : MonoBehaviour { [SerializeField] private Button addButton; [SerializeField] private Text countLabel; private int count; private void Awake() { if (addButton == null || countLabel == null) { Debug.LogError("Assign a uGUI Button and Text.", this); enabled = false; } } private void OnEnable() { if (addButton == null || countLabel == null) return; addButton.onClick.AddListener(AddOne); Render(); } private void OnDisable() { if (addButton != null) addButton.onClick.RemoveListener(AddOne); } private void AddOne() { count++; Render(); } private void Render() { countLabel.text = "Count: " + count; } }