private void OnMouseDown()
{
var buttons = FindObjectsOfType<DefenderButton>();
foreach(DefenderButton button in buttons)
{
button.GetComponent<SpriteRenderer>().color = new Color32(41,41,41,255);
}
GetComponent<SpriteRenderer>().color = Color.white;
}
We define any objects with the DefenderButton script as a “buttons” variable and then use a foreach loop to say each “button” inside a “buttons” in the “buttons” array we will do {this line of cod}
But how does it know what a “Button” is? We never defined or labeled these buttons as buttons (or at least didn’t) and it still works anyway.
I did not change the name of my button’s either and they still work without having to tag or label them as a “button”
I must be missing something here… And why do we state the defender class script before writing button in buttons?