Book Image

OUYA Game Development by Example

By : John Donovan
Book Image

OUYA Game Development by Example

By: John Donovan

Overview of this book

The OUYA console and development kit gives you the power to publish video games for the players, creating a console marketplace of the gamers, for the gamers, and by the gamers. Using the OUYA developer kit and the Unity3D game engine, even beginners with a captivating game idea can bring it to life with a hint of imagination. OUYA Game Development by Example uses a series of feature-based, step-by-step tutorials that teach beginners how to integrate essential elements into a game engine and then combine them to form a polished gaming experience.
Table of Contents (18 chapters)
OUYA Game Development by Example Beginner's Guide
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – counting cannonballs


As with all data operations, the first step is to create a variable that stores the data you want to interact with. To count the number of cannonballs that the player fires, we'll need to use an integer variable with a script that increments the count by one every time the FireCannon function is called. Perform the following steps to count cannonballs:

  1. Create a new C# script named ScoreKeeper, and attach it to your Cannon prefab.

  2. Automatically add the script to all future instances of your Cannon prefab by clicking on Apply in the Inspector window after you attach the script.

  3. Open the ScoreKeeper script, declare an int variable named numCannonballsFired, and initialize it to 0 in the Start function as shown in the following code:

    private int numCannonballsFired;
    void Start()
    {
      numcannonballsFired = 0;
    }

    Next, we need a public function that will increment the integer value by one every time it's called.

  4. Create a new function named IncrementCount and add...