If "equals" doesnt work.

In this script you can see how time goes up from 0 (using Time.deltaTime).
In my case,i want that unity prints massage for me when time is exactly 35 (FirstPass)
Function works if time is greater than or less than Firstpass,or second or third.
But when i want that time is exactly equals to FirstPass,which is 35…the massage is not showing…
By the way it works only when i disable time counting up and enter the value manually…
Why? Please.

#pragma strict

 var time : float = 0.0f;
 var FirstPass : float = 35.0f;
 var SecondPass : float = 45.0f;
 var ThirdPass : float = 55.0f;
 
 var SpeedOfTime : float;
 

function Update ()
{
   
  //if(Input.GetKeyDown(KeyCode.Space))
    
   TimeStarts();
   time += Time.deltaTime * SpeedOfTime;
}


function TimeStarts ()
{

    if(time == FirstPass)
    {
        
        print("FirstPass");
    }
   
    if(time > SecondPass)
    {
        
        print("SecondPass");
    }

    else if (time == ThirdPass)
    {
        
        print("ThirdPass");
    }
}

You’re testing in an Update,
The condition will basically never work, because it’s changing so fast odds are it’s going to skip the exact value.

In the Update it’s always best to test for <= or >=, that way you can be sure that the value passed, or better, find a different approach for your tests.

Cheers (y)

Most of the time it won’t work because the value of time won’t be the exact value that you defined in your variables. It is mostly likely that you could get a result like this; time = 35.00000123 and your FirstPass = 35.00000000 which these two values don’t match. What you can do is comparing these two values with the following, either you comparing using Mathf.Approximate or just Round your time value using Mathf.Round and it will be all fine then.

Because there’s only a very small chance of that line of code being executed in a frame after the game has been running for exactly 35 seconds…