Implemented both dice selections
This commit is contained in:
parent
2b08dc425f
commit
d04624edfd
9 changed files with 182 additions and 29 deletions
|
|
@ -6,13 +6,55 @@ using UnityEngine.UI;
|
|||
public class Die : MonoBehaviour
|
||||
{
|
||||
private int _result = 0;
|
||||
[SerializeField] private Button dieButton = null; // assign in the editor
|
||||
public event EventHandler<Die> DieClicked;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
dieButton.onClick.AddListener(() => { DiePressed();});
|
||||
}
|
||||
|
||||
public void SetResult(int result) {
|
||||
_result = result;
|
||||
gameObject.GetComponentInChildren<TextMeshProUGUI>().text = _result.ToString();
|
||||
}
|
||||
|
||||
public int GetResult()
|
||||
{
|
||||
return _result;
|
||||
}
|
||||
|
||||
public void ClearDie() {
|
||||
gameObject.GetComponent<TextMeshProUGUI>().text = String.Empty;
|
||||
}
|
||||
|
||||
public void DieBeingUsed(bool isFirstPair, 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<Outline>().enabled = true;
|
||||
}
|
||||
|
||||
private void DieSelectedAndPairComplete()
|
||||
{
|
||||
gameObject.GetComponent<Image>().color =
|
||||
ColorHelper.AddColorTint(gameObject.GetComponent<Image>().color, ColorHelper.OkayGreen, 0.5f);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue