Infinite loop: while(Time.time < Time.time + 5f)

Viewed 85

I am going insane. For the life of me I cannot work out why the following code is causing Unity to freeze up as soon as I press play. It's an otherwise empty project with the script attached to an empty gameobject. In the console, nothing appears, not even the initial Debug.Log("Step 1");

using UnityEngine;

public class Reels : MonoBehaviour
{    void Start()
    {
        Debug.Log("Step 1");
        TestFunction(1f);
    }

    private void TestFunction(float duration)
    {
        float endTimer = Time.time + duration;
        Debug.Log("Step 2 " +  endTimer);

        while (Time.time < endTimer)
        {
            Debug.Log("Step 3");
        }
    }

    void Update()
    {

    }
}

Please save my sanity.

1 Answers
Related