- Home /
Time Since Event?
Been working on GUI fade in and fades out this past week and also enabling and disabling them which all works fine and saves on performance.
However the method I am using to do this is the Time.time function.
This works beautifully except Time.time will start whenever the game is played.
What I is to get a realtime measurement that starts only when a trigger is entered or exited.
Once I get this value I can then fade in/out my GUI against this.
Further more I could use it to go one step further and measure the amount of time since a button press and use that to fade other GUI's in and out.
Is there anyway of doing this?
Answer by cj_coimbra · Nov 07, 2011 at 12:16 PM
To make a realtime measurement you need to store the Time.time value of the moment of the event you want to track, and then check for Time.time - your_event_time .
In the button case you mentioned, you could do something like:
//OnGUI
float fadeDelayInterval = 3.0f;
float buttonPressTime;
if (GUI.Button(...))
{
buttonPressTime = Time.time;
}
//then somewhere probably in your Update
if (Time.time - buttonPressTime >= fadeDelayInterval)
{
DoTheFade();
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613034107im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
fade in out multi images then go to next scene 1 Answer
GUI buttons glow/flash/fade between textures 0 Answers
Fade In GUI on proximity 1 Answer
Who Killed Who - Scrolling GUI Text 2 Answers
Delay Player From Using Action Button For A Period Of Time 0 Answers