- Home /
Display gui box after trigger is activated?
Hello I am making a 2D game and I would like to know how to make a gui box (the default gui things) appear after a trigger is activated. This is my script (I have two ones since I have a gameobject to display the guibox) The first script is named "badsweet"
#pragma strict
var offsetY : float = 40;
var sizeX : float = 100;
var sizeY : float = 40;
function OnGUI ()
{
if (youdied1.guiShow == "true");
{
GUI.Box (new Rect (Screen.width/2-sizeX/2, offsetY, sizeX, sizeY), "You Died, Press R to Restart Level");
}
}
The second one is called "youdied1"
#pragma strict
static var guiShow;
function OnTriggerEnter2D (other : Collider2D)
{
if(other.tag == "Player")
{
guiShow = true;
}
}
function OnTriggerExit2D (other : Collider2D)
{
if(other.tag == "Player")
{
guiShow = true;
}
}
With the code applied as it is now the gui box is constantly being displayed.Sorry if this sounds overly complicated. Thanks
Answer by chintan_shroff · Feb 13, 2015 at 01:42 AM
it constantly shows because you have not initiated the bool guiShow as false in the beginning of the code.
static var guiShow = false;
Thanks, being on these forums is so enlightening. I am very new to program$$anonymous$$g and Unity and am trying to learn more everyday. Thanks again
Answer by EightbitPoe · May 21, 2015 at 04:26 PM
I'm not used to javascript, but try using
if (youdied1.guiShow)
or
if (youdied1.guiShow == true)
I guess that may be the problem
Your answer
Follow this Question
Related Questions
OnTriggerEnter/Exit called unexpectedly 2 Answers
Trigger on MeshCollider Only Seems To Work at Edges of Mesh 1 Answer
Get WHICH trigger for OnTriggerEnter? 1 Answer
Get a texture to appear, always facing the camera, when a trigger is entered? 1 Answer
OnTriggerExit overwrites OnTriggerEnter 2 Answers