i have a game in which there are 3 buttons and I need to save them in form of arrays or string so that I can randomly access there properties.
I can name those buttons ( butt1, butt2, butt3) and set them public but I still don’t know how write them in script. Please help
You can create a Tag for those buttons (“ButtonTag”), and in the Start method you can Find them by doing :
GameObject buttonsList = (GameObject) GameObject.FindGameObjectsWithTag(“ButtonTag”);
then you can access the Button component as such:
Button button1 = buttonList[0].GetComponent();
You can also define a public var to be shown in the Inspector and just click and drag your buttons from the hierarchy view to the inspector var.
There are several ways to keep track of your vars and objects, you just have to find the one which suits you the best.
first really thank you for helping me. But your code(small button code) that you gave me doesn’t seem to work.it is showing this error(Assets/New Folder/scripts/DisplayColor.cs(19,33): error CS0029: Cannot implicitly convert type int' to
UnityEngine.Color)
- Your example scene you gave me was empty ( i don’t know if you were joking or what).