- Home /
GUI Button not displaying an icon
It sounds like a simple process but for some reason I cannot get a GUI button to show an image. I have the button appearing but it is just gray, and I have linked the variable to the texture in the inspector, am I missing a step?
var icon1 : Texture2D;
function Update ()
{
}
function OnGUI ()
{
GUI.Button (Rect (0, 0, 128, 128), icon1);
}
Answer by Anxo · Jun 08, 2011 at 04:50 PM
check to make sure your vector2 is not out of the screen.
try GUILayout.Button just to see if it is the texture or your vector2 that is the problem.
and buttons I think need to be in an if statement in gui so it would be
if(GUI.Button(Rect(......
This helped me out alot actually. After putting in some Debug info it was telling me that a texture was not being assigned in the inspector, which led me to find that the script itself was not bound to a proper Game Object. After moving the script, the button and image appeared together. Thanks Guys
Answer by Bunny83 · Jun 08, 2011 at 04:12 PM
Well, it should work that way. Have you imported the texture as texture type GUI? It should be visible anyway. What format do you use for the texture?
Yes I did set it to GUI, I tried others as welll just to check but still no luck. The image itself is a PNG but I tried GIF and JPEG as well.
Your answer
Follow this Question
Related Questions
How Do I Make GUI ON Off Button with 2 Button States 3 Answers
Button function Problems 1 Answer
How to make a custom GUITexture at runtime? 2 Answers
Scaling a 2D Texture (Image) 0 Answers