- Home /
make GUI texture disappear after a few second ?
Hi i have a problem with a script. i made this:
var toggleGUI : boolean;
var textureToDisplay : Texture2D;
function OnTriggerEnter (other : Collider) {
toggleGUI = true;
}
function OnTriggerExit (other : Collider) {
toggleGUI = false;
}
function OnGUI () {
if (toggleGUI == true)
GUI.Label (Rect (500, 200, textureToDisplay.width, textureToDisplay.height),
textureToDisplay);
}
It display a texture when I'm in a trigger but i want the texture disappear (not destroy) after a few second (like 3sec) but don't know how to do this =s
Tank you in adavance ;)
So you want to have this only occur once? And you want a slow fade?
In other words, the first time you enter the trigger, the image displays but it does not any time after that?
And yeah, please change that answer to a comment.
Sry, didn't notice the difference between answer and comment :s
I have a door to open. I display a message who explain wich key open the door. So i use the script and it's work (disappear after 3sec) but when i come back near my door ( to close this one for exemple) the guitexture display but the gui texture still display even after the 3 second Sry for my bad english =s
So you only want it to display for 3 seconds if you execute again? Not sure I follow.
Yes, each time I enter in my trigger i want my GUI texture display just for 3seconds
Your script work fine but just work once (if i come back in trigger, the GUI texture don't disappear)
Answer by brandonsbarber · Jul 11, 2013 at 07:23 PM
Well, first off, since toggleGUI
is already a boolean, you do not need to compare it to true
or false
in OnGUI. Instead, you only need to put:
if(toggleGUI)
That aside, we come down to your issue. Instead of simply toggling toggleGUI
, you can use
yield WaitForSeconds(3.0);
toggleGUI = false;
This way, you will pause the function until it is toggled.
EDIT:
If you want the message to only display for 3 seconds, put the above script just after you set toggleGUI
to true. And remove the OnTriggerExit
For more information, check out the documentation here
that work nice, thank you !! But that work just one time if i come back on my trigger, the GUI textrue still display. How can i fixe this? And is it possible ton fade out slowly? (easy way not hard code ^^) Thx in adavance
if someone need this kind of script, it's the final script:
var toggleGUI : boolean;
var textureToDisplay : Texture2D;
function OnTriggerEnter (other : Collider)
{
toggleGUI = true;
yield WaitForSeconds(2.0);
toggleGUI = false;
}
function OnGUI () {
if (toggleGUI)
GUI.Label (Rect (500, 200, textureToDisplay.width, textureToDisplay.height),
textureToDisplay);
}
Your answer
Follow this Question
Related Questions
Guitexture appear/disappear 1 Answer
GUI Textures disappearing (on buttons) 1 Answer
Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer
GUITexture disappears in build 0 Answers
pickup count on GUI 1 Answer