We need time is in the VR course to automatically progress from one level to the next. So as an example in this blog post I am going to be using the LevelManager script. The full code to the script is at the end of the post.
The approach I'm going to outline in this post involves storing a countdown timer. The type of this countdown timer is a float as that's the type we use for time in Unity. On each run round the update method we have to decrement by the frame time. This is given in Unity by Time.deltaTime.
To check whether the time has expired we simply need to check that countdown variable is negative. When this condition is met, in our example we simply load the next level.
The outline that I have given is in the code snippet below.
The way I achieve this is by writing the entire check in an if-statement. This if-statement checks that the counter is positive. If it is not positive then we do not increment and we do not check the negative.
This gives us the desired behaviour and has the side-effect that the trigger event, In our case loading the next level, only ever gets called once. This is exactly when the step of decrementing the timer takes the time from positive to negative.
Below is the entire LevelManager script.