using System; using UnityEngine; public sealed class EventCounter : MonoBehaviour { public event Action ScoreChanged; private int score; private void OnEnable() { ScoreChanged += ReportScore; } private void OnDisable() { ScoreChanged -= ReportScore; } [ContextMenu("Add One Point")] public void AddOnePoint() { if (!Application.isPlaying) { Debug.LogWarning("Enter Play mode first.", this); return; } score++; if (ScoreChanged != null) ScoreChanged(score); } private void ReportScore(int value) { Debug.Log("Score: " + value, this); } }