Learn Unity 2017 for iOS Game Development by Allan Fowler & Philip Chu

Learn Unity 2017 for iOS Game Development by Allan Fowler & Philip Chu

Author:Allan Fowler & Philip Chu
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA


Tracking the Game

Listing 8-15 shows the variables defined in the FuguBowl script to track the current frame and current ball.

private var state:String; // current state in the state machin

enum Roll {

Ball1,

Ball2,

Ball3

}

Listing 8-15.The Variables in FuguBowl.js That Track the Current Frame and Ball

The variable frame tracks the current frame with an int, ranging from 0 to 9 instead of 1 to 10 because that number will be used as an array index when it’s passed to the FuguBowlPlayer functions.

The variable roll tracks the current roll of the ball and could also have been declared an int, choosing a convention where the numbers 0 to 2 or 1 to 3 represent the three possible balls in a frame. But it’s cleaner to define an enum (short for enumeration), which essentially allows you to define a new type where the value is one from a list of named values. So, roll is declared to be of type Roll, which is an enum with values Ball1, Ball2, or Ball3.

By the way, at this point you’ve encountered several different categories of types: primitive types like int and boolean, built-in arrays that contain other types, enums like the Roll enum, structs like Vector3, and classes like GameObject, Component, and FuguBowlPlayer. Of these categories, classes and arrays are reference types, meaning different variables can reference the same instance of that type, and modifications to the instance will be visible through every variable referencing that instance.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.