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 button features


Kindly perform the following steps to add button features to our marble:

  1. Add one new line each to the OUYA and non-OUYA code for applying a jump force to the rigidbody of our marble. The Update function will now look as follows:

    void Update ()
    {
    #if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR
      moveVector.x = -Input.acceleration.y + Input.GetAxis("Horizontal");
      moveVector.z = -Input.acceleration.x + Input.GetAxis("Vertical);
    
      if(Input.GetKeyDown(KeyCode.Space))
      {
        moveVector.y = 50.0f;
      }
      else
      {
        moveVector.y = 0.0f;
      }
    #else
      //OUYA-specific code goes here
      moveVector.x = -Input.acceleration.y +
                        OuyaInput.GetAxis(OuyaAxis.LX, OuyaPlayer.P01);
      moveVector.z = -Input.acceleration.x + OuyaInput.GetAxis(OuyaAxis.LY, OuyaPlayer.P01);
    
      if(Input.GetButtonDown("Jump"))
        moveVector.y = 50.0f;
      else
        moveVector.y = 0.0f;
    #endif
      rigidbody.AddForce(moveVector * speed * Time.deltaTime);
    }

The non...