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.

  1. Edit BeginState as shown in the following screenshot.
  2. Save and play in Unity.
    Time for action – creating a timer in BeginState

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 ...

Get Learning C# by Developing Games with Unity 3D Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.