- Home /
Question by
bekiryanik · Sep 17, 2014 at 03:29 PM ·
guigui.buttonguibutton
How to change GUI.Button Texture?
Hello,
I want to change GUI.Button texture.
Here is example codes:
[code]
if (GUI.Button (nextB.rect, "", skin.GetStyle("nextButton")))
{
// In this part, i want to write some code which will change the texture of button.
// Actually, this button will be inside of "Character Select" screen and on last character, button will change and will seem like deactivated.
}
[/code]
Thank you.
Comment
Best Answer
Answer by bekiryanik · Sep 17, 2014 at 07:08 PM
Maybe, yours was the solution but i couldn't be successful with it. Thanks for the answer! Here is what i did:
if (nextButtonBool && GUI.Button (nextB.rect, "", skin.GetStyle("nextButton")))
{
if(charNo == 2)
{
anim.SetInteger( "charNO", 2);
nextButonBool = false;
}
}
if(!nextButtonBool && GUI.Button (nextB.rect, "", skin.GetStyle("nextButton2")))
{
}
This works very well.
Answer by robertbu · Sep 17, 2014 at 04:34 PM
Not sure if this is right way to do what you are asking, but you can create a duplicate GUIStyle and modify the background texture:
private var gs : GUIStyle = null;
var tex : Texture2D;
function OnGUI() {
if (gs == null) {
gs = new GUIStyle(skin.GetStyle("nextButton"));
gs.normal.background = tex;
}
GUI.Button(Rect(50,0,200,50), "Original style");
GUI.Button(Rect(50,100,200,50), "New style", gs);
}