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…
- Time.time is read only, and shows me the Time passed since my Scene started if I have it in start function.
- 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”);
}
}