- Home /
How to change a GUI button texture through scripting
Our GUI has several buttons on the layout. What I'm trying to do is change the texture of the button based on whether or not a specific boolean is true or not. I've looked through answers and the scripting reference, but haven't found anything that looks like it'd work.
Basically it'd be something like
if (ThirdPersonController.gasMask = true) change texture else use original/normal texture.
I hope you do know that when using an if statement you need to use (boolean == true) and not (boolean = true). Else it wont work :)
I used and really liked the 2nd answer on this post http://answers.unity3d.com/questions/24753/guibutton-texture-swap.html GUI.Button( myRect, myBool ? texture1:texture2 )
Answer by efge · Mar 22, 2011 at 08:39 PM
That's what GUI Skins are made for.
You can set up textures for the states of buttons: On Normal, On Hover, On Active and On Focused and a lot more.
So does this mean that for each different button, you need to have a new GUI.Skin? Appears to be that way.
use skinGui.GetStyle something like this public Rect loginbox; if (GUI.Button(loginbox, "", skinGui.GetStyle("login"))){ your command; }
Your answer
Follow this Question
Related Questions
Cases if a GUI.Button is clicked two or more times?? 2 Answers
Making a Hover function for a button or toolbar from code. 2 Answers
Change button texture when its clicked 1 Answer
Turn off my GUI Box when I click a button. 3 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers