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 – adding an impulse force to a rigidbody component


Force can be applied to any GameObject variable that has a rigidbody component using Unity's AddForce function. In the case of our cannonballs, we want to add force to them as soon as they're instantiated; so in this section, we'll be editing our FireCannon function to include an additional force on any new cannonballs.

To change the properties of an instantiated prefab, we need a variable linked to it. Fortunately, Unity's Instantiate function returns the instantiated prefab, so we can store that in a new local variable in our FireCannon function. Perform the following steps to add an impulse:

  1. Modify the call to Instantiate in your FireCannon function to store the return value in a new GameObject:

    void FireCannon()
    {
      Vector3 cannonballPos = gameObject.transform.position;
      cannonballPos.x += 2;
      cannonballPos.y += 2;
    
      GameObject newCannonball = (GameObject)Instantiate(cannonballPrefab, cannonballPos, Quaternion.identity...