- Home /
Display GUI when enter an area?
When i enter a room how do i make a trigger in that room,
so when i walk in it it displays an onGUI button on screen?
I'm noob at scripting.
thanks in advance.
Answer by syclamoth · Jan 07, 2012 at 02:55 AM
Make a large box collider with 'isTrigger' set to true.
In your 'OnTriggerEnter' function, do something like this-
if(collider.gameObject.tag == "Player")
{
triggered = true;
}
and then in your OnGUI-
if(triggered)
{
// draw something!
}
Obviously this isn't completed code, but it should be enough to let you work out the rest.
Answer by snowconesolid · Jan 07, 2012 at 03:13 AM
There are many different ways of doing this.
You can make a cube, give it a tag and flatten it down and then place it on the floor where the player would walk, you can place it right in the beginning of the room. Then just uncheck Mesh Renderer to make it invisible, Then you can use a collider in script and make it something like this:
gameObject.Find("Your Gui Name").guiTexture.enabled = false;
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.gameObject.tag == "GuiTrigger" )
{
gameObject.Find("your GUI name").guiTexture.enabled = true;
}
}
So Basically the Gui is not enabled, but once the player touches the the invisible box the GUI would become enabled and show on screen.
Im Not sure if this will work, but you would do something similar to it. But actually I have a good feeling this is the right code to use and it should work. I would of tested it out but cant at the moment.
Your answer
Follow this Question
Related Questions
Display a Text/GUI on screen when triggerd with Fadein/Fadeout 1 Answer
Displaying Z Rotation through script 1 Answer
Why can't void be used in this context? 2 Answers
getting gui error you can only call functions from inside OnGui. 1 Answer
Show GUI Texture on Trigger and Instantiate Object if Button pressed while In Trigger? 1 Answer