O'Reilly logo

Learning C# by Developing Games with Unity 3D Beginner's Guide by Terry Norton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required