I have some standard GUI buttons and I need to change the images associated with them in other parts of a script. Problem is, I cannot find a way to reference these buttons later in a script.
For example, I can update the button’s image when I create the button like this:
But how can I change that button’s image elsewhere? Can I create a name for that GUI.Button object somehow then access it’s “image” property? I looked in the documentation but could not find anything.
No, I don’t think that will work as buttons and objects in our GUI system are not objects that can be referenced like that. Instead look to have some variables that you store that reference the texture you’d like to display in your button. Then your other script simply points that variable to a new texture so the button displays it.
var MyTexture : Texture2D;
function OnGUI () {
var SomeRect = ...;
if (GUI.Button(SomeRect, MyTexture)) {
...
}
}
Something like the above, then your other script changes the value of MyTexture.