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 a vector from cursor movement


Our cannonballs are propelled by an initial force that we create using the X and Y elements of the AddForce vector. Up until this point, the two values were set at a constant value of 12.5, creating the same velocity and angle each time.

In this section, we'll use the change in the X and Y values from our cursor to affect the dynamic X and Y values in our firing function so that the velocity and angle are affected by the way the cursor is moved. Perform the following steps to create the vector:

  1. Declare two new float variables called mouseX and mouseY next to the other variables in your CannonScript.cs file as shown:

    private int buttonWidth;
    private int buttonHeight;
    private string buttonText;
    public GameObject cannonballPrefab;
    
    private float mouseX;
    private float mouseY;
  2. Create a new function called CaptureTouch in CannonScript.cs using the following code:

    void CaptureTouch()
    {
    
    }

    As swipe gestures happen over multiple frames of our game...