if (GUI.Button(new Rect(10, 10, 50, 50), btnTexture))
{
Debug.Log(“Clicked the button with an image”);
}
Please read this b4 posting.
http://forum.unity3d.com/threads/97860-Read-this-before-posting-questions-in-the-scripting-section?p=638874#post638874
Give more details on what you are trying to do. Post some screenshots and put your snippets in a code tag.
And according to your codes, i don’t see any problems.
Perhaps try this.
var btnTexture : Texture;
function OnGUI()
{
if (GUI.Button(new Rect(10, 10, 50, 50), btnTexture))
{
Debug.Log("Clicked the button with an image");
}
}
Then in your inspector remember to assign btnTexture. ![]()
To do this you’d need to use a GUIContent
GUIContent content = new GUIContent( btnTexture );
if (GUI.Button(new Rect(10, 10, 50, 50), content))
{
Debug.Log("Clicked the button with an image");
}
This will put the texture specified as a icon ( depending on the “button” GUIStyle )
Avoid creating a new GUIContent every call though and just change the type of btnTexture to GUIContent.
If your wanting to instead replace the button image ( background/ border) you’ll need to use GUIStyle insteadl of GUIContent ( change the type of btnTexture to GUIStyle and use like this
GUI.Button(new Rect(10,10, 50, 50), GUIContent.none, btnTexture )