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 keyboard interaction to scripts


Perform the following steps to add keyboard interaction to your scripts:

  1. Add the following if statement to your Update function that checks if the Return key is pressed:

    // Update is called once per frame
    void Update()
    {
      if(Input.GetKeyDown(KeyCode.Return))
      {
    
      }
    }

    Everything contained within the if statement will run every time the Update function detects that the Return key has just been pressed down (there's a slightly different way to check if a key is being held down, but we'll cover that in the next chapter).

    We could add code directly inside the if statement to change the color of the text, but it's better to write a function for an action like that in case you want to replicate the same functionality outside of that if statement without writing redundant code, so we'll create a dedicated ChangeColor function.

  2. Declare the ChangeColor function below the Update function in your ColorChanger script, as shown in the following code...