I have a multiple button that has an image in it, whenever a button is being clicked it changes color, but I have a condition to test and I also want to change the color of the Image attached to the Button objects when the condition is false. But if the condition is true I want to destroy the all the clicked Button Objects and Instantiate new ones. How would I properly do that? I have tried so many ways, but it all doesn’t work.
The Condition on my game manager script:
public void checkword()
{
wordBuilded = displayer.text.ToString();
if (txtContents.Contains(wordBuilded))
{
Debug.Log(wordBuilded + " Is on the list");
FindObjectOfType<LetterTiles>().validWord();
}
else
{
Debug.Log("Someting is wrong..");
FindObjectOfType<LetterTiles>().invalidWord();
}
}
The script attached to every Button object:
using UnityEngine;
using UnityEngine.UI;
public class LetterTiles : MonoBehaviour {
public string letter;
public GameObject tile;
Color32 tColor = new Color32(255, 215, 86, 255);
Color32 origColor = new Color32(255, 250, 210, 255);
public void letterClick()
{
gameManager.currentWord += letter;
gameObject.GetComponent<Image>().color = tColor;
}
public void invalidWord()
{
gameObject.GetComponent<Image>().color = origColor;
}
public void validWord()
{
Destroy(gameObject);
}
}