- Home /
Question by
Bdogup · Feb 01, 2015 at 05:55 PM ·
guitexture
GUI Texture Pop-Up Script Error??
I need a GUI Pop-Up script which Pops-Up with a Texture while Inside of a Collider. I have made the Entire script but, for some reason I get an Error (I have no Idea what the Error is so, you may need to test it :(). Can anyone tell me why the script won't work? I really need this for a children's game I am working on! Thanks for the Help!
Brady
Script:
#pragma strict
private var guiShow : boolean = false;
var GUI : Texture;
function OnTriggerStay (Col : Collider)
{
if(Col.tag == "EarthGUIAtmosphere")
{
guiShow = true;
}
}
function OnTriggerExit (Col : Collider)
{
if(Col.tag == "EarthGUIAtmosphere")
{
guiShow = false;
}
}
function OnGUI()
{
if(guiShow == true)
{
GUI.DrawTexture(Rect(Screen.width / 4.5, Screen.height / 4, 1024, 512), GUI);
}
}
Comment
Best Answer
Answer by JJNCreator · Feb 02, 2015 at 04:43 PM
I haven't tested your code, but if you're using OnTriggerStay, the collider you're using needs a rigidbody. But you can use OnTriggerEnter to make guiShow
true. It's pretty much the same thing as OnTriggerStay, except it doesn't need a rigidbody, and it should make guiShow
true upon being called. I would try using this code:
#pragma strict
private var guiShow : boolean = false;
var GUI : Texture;
function OnTriggerEnter (Col : Collider)
{
if(Col.tag == "EarthGUIAtmosphere")
{
guiShow = true;
}
}
function OnTriggerExit (Col : Collider)
{
if(Col.tag == "EarthGUIAtmosphere")
{
guiShow = false;
}
}
function OnGUI()
{
if(guiShow == true)
{
GUI.DrawTexture(Rect(Screen.width / 4.5, Screen.height / 4, 1024, 512), GUI);
}
}
Hope it helps