How can I get a fixed time value with using Time.time?

How can I get a fixed time value out of Time.time and compare it with a defined float?

I really don´t know if I understand Time.time right, so if I something here is wrong pleas correct me…

  1. Time.time is read only, and shows me the Time passed since my Scene started if I have it in start function.
  2. If I want to use a Trigger to display the current Time at the triggering I do :

function OnTriggerEnter()

{

timeOnHit = Time.time;

Debug.Log(“TheTimeOnTriggerHit” was: + timeOnHit);

}

3.But if I understand right my “timeOnHit” variable is not saved with the value it has at the Debug.Log because if I try to compare it to a float nothing happens:

function OnTriggerStay()

{

if(timeOnHit - Time.time >= 1.0)

{

Debug.Log(“Time passed”);

}
}


Also this is not working in a new project on a simple cube attached:

var startTime;

var timeOnHit;

//

function Start()

{

startTime = Time.time;

}

//
function OnMouseEnter()

{

timeOnHit = Time.time;
	Debug.Log("TheTimeOnTriggerHit was: "+ timeOnHit);

}

//

function OnMouseDown()

{

Debug.Log(“Mouse is Down”);

if(startTime - timeOnHit >= 1.0)

{

Debug.Log(“Time passed, IF statement executed”);

}

}

Try:

if(Time.time - timeOnHit >= 1.0)

The code you have currently will always render a negative number since Time.time will be greater than timeOnHit.

It’s always worth Debug.Log()ing the results used in comparisons when things don’t go quite as you’d expect them to; noticing that variables are the wrong way round is often an easily missed mistake and you would have soon noticed your error this time around.