Time for action – creating a timer in BeginState
I've modified BeginState
quite a bit just for the timer. There are now three examples of ways to switch to PlayState
. Plus, there's a timer countdown displayed in the upper right corner. I also put code that I had to write more than once into a new Switch()
method.
Edit
BeginState
as shown in the following screenshot.Save and play in Unity.
What just happened?
I'm not going to walk you through the State switching code, I already did that previously.
An analysis of the code shown in the preceding screenshot is as follows: On the BeginState
class
For lines 9, 10, and 11:
Three member variables are declared for use in the countdown timer
These will be explained later when they are used in code
The reason they are declared here as member variables is that they need to be used in more than one method
Remember the variable scope, variables are only visible within the code block they reside in
Line 16: futureTime = screenDuration + Time.realtimeSinceStartup...