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 – controlling functions with parameters


Our functions now communicate back to us, but we still haven't communicated to our functions; that's where input parameters come in. Declaring parameters in your function declaration requires the presence of one or many values, without which it couldn't function. For instance, if we wanted our MoveObject function to move the target game object to a different distance each time we called it, we could make that distance one of the required parameters, so each function calling MoveObject will need to tell it how far to translate. Perform the following steps for controlling functions with parameters:

  1. Remove the declaration for translationValue on the top line of the MoveObject function and declare a distance parameter, as shown in the following code:

    float MoveObject ( float translationValue )
    {
      gameObject.transform.Translate(translationValue, 0.0f, 0.0f);
      return translationValue;
    }

    We can still refer to the variable translationValue because...