I was trying to use C# as my first try on Unity. I just forgot it and begin to learn using javascript, because I couldn’t find proper docs and because I don’t know Unity well enought.
Anyway… I’m trying here to change a buttons text after user clicks it.
How can I do it?
My Code:
if (new GUI.Button(Rect(10,10,150,30),"Turn Light 1 OFF"))
{
GameObject.Find("Light1").GetComponent(Light).enabled = true;
}
I want to change its text to something like “Turn Light 1 ON”.
I can hardly understand the code, but i think you may want light the button where the mouse is on, don’t you?.
Because if is that, you would prefer avoid read an array and try this (pseudocode)…
//1
if (buttonAux != null) buttonAux.enable = off
//2
buttonAux = currentLight
//3
buttonAux.enabled = true
The idea is to store the reference of current light into buttonAux; 1) at first it will be null and will skip the IF sentence, 2) but inmediately it will store the current light (still off).
After store the reference, 3) you will turn enabled buttonAux variable, and it will get turned on.
When you move the mouse over another button, the method will turn the light inside buttonAux off, and will continue the cylce from 2).