using System; using TMPro; using UnityEngine; using UnityEngine.UI; public enum DiceColor { Black, White, } public class Die : MonoBehaviour { public DiceColor color; private int _result = 0; [SerializeField] private Button dieButton; // assign in the editor private Color originalColor; public event EventHandler DieClicked; private void Start() { dieButton.onClick.AddListener(() => { DiePressed();}); originalColor = gameObject.GetComponent().color; } public void SetResult(int result) { _result = result; gameObject.GetComponentInChildren().text = _result.ToString(); } public int GetResult() { return _result; } public void ResetDie() { gameObject.GetComponent().color = originalColor; gameObject.GetComponent().enabled = false; } public void DieBeingUsed(bool isPairComplete) { if (isPairComplete) { // Signify that both dice have been selected DieSelectedAndPairComplete(); } else { // Signify that the die is selected but the pair is not complete DieSelectedButPairNotComplete(); } } private void DiePressed() { DieClicked?.Invoke(this, this); } private void DieSelectedButPairNotComplete() { gameObject.GetComponent().enabled = true; } private void DieSelectedAndPairComplete() { gameObject.GetComponent().enabled = false; gameObject.GetComponent().color = ColorHelper.AddColorTint(gameObject.GetComponent().color, ColorHelper.OkayGreen, 0.5f); } }