0

if (nextActionTime == timeToEngineProblem && !generateProblem) // I need to check this, but it doesn't work the "timer" is still counting but doesn't check

This is what I do: ...

 [SerializeField] float nextActionTime = 0f;
    [SerializeField] private float periodTime = 0.1f;
    [SerializeField] float timeToEngineProblem = 10f;
    [SerializeField] bool generateProblem;
void Update () 
{ 
  if (Time.time > nextActionTime) 
   {  nextActionTime += periodTime; 
     Debug.Log("Time: " + nextActionTime);        
     if (nextActionTime == timeToEngineProblem && !generateProblem) // There is what i need to check
        {
            Debug.Log("The problems begin");
            generateProblem = true;
            TruckEngineProblem();
        }

    }

}
Mayur Kamble
  • 180
  • 4
  • 2
    Be careful with `==` and `float` ... also see the [floating point guide](https://floating-point-gui.de/errors/comparison/). – Fildor Dec 12 '22 at 14:47

0 Answers0