- Home /
how can i change the gui button on runtime??
I am trying to create a level unlocking screen in which I am using two images one for the unlocked levels till where the user has cleared the level and another for the locked levels which has not been played till now.
I want to get my image clickable.i could have done this quiet easily if it was about a single image but i have to work conditionally on two images.So can anyone please tell me how to change the button image using Single guiskin.I mean how can i change it on runtime??
Answer by DESTRUKTORR · Sep 02, 2013 at 05:05 PM
if(someBool)
{
myGUISkin.button.normal.background = normalTexture1;
myGUISkin.button.hover.background = backgroundTexture1;
//... etc, for all the various textures involved with buttons
}
else
{
myGUISkin.button.normal.background = normalTexture2;
myGUISkin.button.hover.background = backgroundTexture2;
//... etc, for all the various textures involved with buttons
}
However this can be a bit tedious, so I might suggest using an additional GUIStyle that you create, and calling that when you call `GUI.Button`.
Find more documentation on this stuff on the following pages:
GUISkin: This is what allows control of a GUISkin, programmatically.
GUIStyle: This is what GUISkins essentially serve to contain (used to format various GUI components).
GUIStyleState: This is used to determine the actual state of a component of a GUIStyle, and what contains the texture, and text color variables for several of GUIStyle's components.
Your answer
Follow this Question
Related Questions
How to make gui image button revolve 2 Answers
Look like a Website Menue! 1 Answer
GUI.Button simple dropdown menu problem 0 Answers
How to create a gui button inside an if statement? 1 Answer
Checking for idle hover using tooltips 0 Answers