Book Image

Unity Game Development Blueprints

By : John P. Doran
Book Image

Unity Game Development Blueprints

By: John P. Doran

Overview of this book

Table of Contents (16 chapters)
Unity Game Development Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating an Options menu


Something that many games also need is an Options menu, so let's create it by performing the following steps:

  1. Go back into our PauseMenu script.

    The first thing we're going to want to do is add an additional variable, but we can't use a Boolean value (true/false) because we want an option of one of three constant things. We could create an integer and do something if the value is 0, something else if 1, and something else if it is 2. However, that wouldn't look very elegant and would require us to memorize the values we associate with a particular thing. To solve these issues, we will instead create an enumeration. Enumerations, often referred to as enums, are a distinct type that we create, that is, they are themselves a collection of constant values. Place the following two lines after you enter the class:

    enum Menu{None, Pause, Options};
    private Menu currentMenu;

    Notice how we are able to create a variable of the type Menu here; that's because we used the enum keyword...