im trying to use this script to open a window with a texture on it when you press a key.
var visible : boolean;
var windowRect;
var controlTexture : Texture2D;
function Start()
{
visible = false;
GUI.Label (Rect ( 100,120, 1500,780 ), controlTexture);
}
function OnGUI()
{
if( visible )
{
GUI.Box( windowRect, "Map" );
}
}
function Update()
{
if( Input.GetKeyDown( KeyCode.M ) )
{
visible = !visible;
}
}
but it just crashes unity.
any ideas how to fix it?
thanks
Try removing the GUI.Label() call from the Start() function. AFAIK, the GUI object is only valid/accessible in the OnGUI() event.
no luck, still doesnt work.
Does it crash when you Play, or when you press ‘M’.
var visible;
var windowRect;
// Exposed to the editor. I assume you want
// to keep this for later.
var controlTexture : Texture2D;
function Start()
{
visible = false;
// El-Problemador, below. :)
windowRect = Rect( 100,120, 1500,780 );
}
function OnGUI()
{
if( visible )
{
GUI.Box( windowRect, "Map" );
}
}
function Update()
{
if( Input.GetKeyDown( KeyCode.M ) )
{
visible = !visible;
}
}
You didn’t tell windowRect about the rectangle you were trying to draw.
Give it a shot now.
Thanks for this, it has helped a lot.
however, the window pops up fine but the texture does not show. ive tried it with a few different textures and none of them seem to show up.
any ideas?
You need to put:
GUI.Label (Rect ( 100,120, 1500,780 ), controlTexture);
after GUI.Box to get the Label with the texture to appear.
Alternatively: replace GUI.Box() with GUI.DrawTexture().
thanks Tempest that worked great.
what Asvarduil said didnt seem to work, it came up with an error.
thanks guys
Trouch
January 5, 2010, 10:07pm
11
Hey guys i need to use a similar script, tried this one and it wont work
Is it in java code? ( doesn’t look like C# )
keeps telling me script isnt complied yet
It is indeed JavaScript code. Sometimes, when you copy code from a browser, you get unwanted invisible whitespace characters that the compiler doesn’t like. If you’re using Unitron, try looking at the code with the Show Invisible Characters option (on the View menu). If that’s OK, check that you haven’t missed out a closing brace or anything when you copied the text.