Hello all!
I’ve been battling with this for a day or so now but I’m still prety new to C# and can’t figure out what to do next.
I’m trying to add some UI buttons that are on a Canvas to an array so that I can apply some actions to them.
Here’s what I’ve got so far:
public GameObject[] buttonArray;
void Start()
{
buttonArray = new GameObject[4];
for (int i = 0; i < buttonArray.Length; i++)
{
buttonArray *= GameObject.FindGameObjectWithTag("UI_Button");*
}
}
The problem I’m having is that it only finds one of the buttons and adds it 4 times.
gjf
2
use FindGameObjectsWithTag() to get the array for you… so just do
buttonArray = GameObject.FindGameObjectsWithTag("UI_Button");
instead of your for loop.
EDIT: you don’t need to initialize it yourself either