- Home /
Problem Image GUI
Greetings,
I am making a GUI but when I try to create a Label which is a texture, then it doesn't draw the texture. The reason is that in theory mi image is NULL, so there's no image linked to the var.
However, I have attached the image using the inspector, and I don't undestand why this happen. Here is the code:
var Skin : GUISkin;
var img : Texture2D;
var speed : int;
var fuel : int;
var oxygen : int;
var gravity : int;
var coins : int;
function FillLabels(s : String, f : String)
{
flabel=f;
slabel=s;
}
function OnGUI()
{
GUI.skin=Skin;
GUI.Label ( Rect ( Screen.width/2, Screen.height/2, 65, 65 ), img );
}
Try using GUI.Box
.
Besides that, what does Unity's Console window has to say about this? Do you get any errors or warnings?
You can use GUI.DrawTexture as well. $$anonymous$$ake sure that once the game has started that the texture is still in the slot. If its not there, it cant render it. Consider setting up the path to the texture from Awake or Start
Answer by Sdev · Apr 01, 2012 at 10:01 PM
I solved the problem. It was a mistake. I attached the image to the script object in the Project view, instead of the attached script of the object.
Thank you for your help :) ,I have solved the problem finally. It was a mistake. I assigned the image to the script instead of the attached script of the object.
Thank you for your help