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?

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();
    }