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 – creating an interactive button


Now that you've created a cannon prefab, we can start writing scripts for it that use the OUYA controller's touchpad. The first functionality we'll add is an interactive button that makes the cannon fire a cannonball when it's tapped. Perform the following steps to add an interactive button:

  1. Create a new script named CannonScript.cs in your Code folder and attach it to your Cannon prefab.

  2. Open CannonScript.cs in your code editor.

  3. Declare the following variables at the top of the CannonScript class definition, just before the Start function:

    private int buttonWidth;
    private int buttonHeight;
    private string buttonText;
    
    void Start()
    {
    
    }
  4. Initialize each variable with values for our new button in the Start function. Give the button a width of 100, a height of 50, and a "Fire!" text label, as shown in the following code:

    Private int buttonWidth;
    private int buttonHeight;
    private string buttonText;
    
    Void Start()
    {
      buttonWidth = 100;
      buttonHeight...