How to change GUI.Button Texture?

Hello,

I want to change GUI.Button texture.

Here is example codes:

       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.
          }

Thank you.

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);
}

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.