ZoeAppClass/Assets/Jogos/MemoryGame/Scripts/MemoryButtonBehaviour.cs

61 lines
1.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MemoryButtonBehaviour : MonoBehaviour
{
private Button thisBtn;
public int id;
public Sprite thisSprite;
private Animator anim;
// Start is called before the first frame update
void Awake()
{
anim = GetComponent<Animator>();
thisBtn = GetComponent<Button>();
thisBtn.onClick.AddListener(ResolveClick);
}
private void ResolveClick()
{
if (MemoryManager.instance.canPlay)
{
MemoryManager.instance.CompareButtons(this);
anim.SetTrigger("Flip");
}
}
public void SetupButton(int i, Sprite s = null, string t = "")
{
if (s == null)
{
thisBtn.GetComponentInChildren<Text>().text = t;
Color temp = thisBtn.GetComponentsInChildren<Image>()[1].color;
temp.a = 0;
thisBtn.GetComponentsInChildren<Image>()[1].color = temp;
}
else
{
thisBtn.GetComponentsInChildren<Image>()[1].sprite = s;
thisBtn.GetComponentsInChildren<Image>()[1].preserveAspect = true;
thisBtn.GetComponentsInChildren<Image>()[1].color = Color.white;
thisBtn.GetComponentInChildren<Text>().text = t;
}
id = i;
}
public void DoDeactivate()
{
anim.SetTrigger("Bye");
thisBtn.interactable = false;
}
public void DoFlip()
{
anim.SetTrigger("Unflip");
}
}