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 – writing a function


In this tutorial, you'll begin writing your own functions and calling them to be executed. Perform the following steps to write a function:

  1. Create a new script in the same way you created the color-changing script, but name it ObjectMover. Open the script and add the function declaration named MoveObject below the declaration for Update, so that your full code file appears as shown in the following code:

    using UnityEngine;
    using System.Collections;
    
    public class ObjectMover : MonoBehaviour
    {
      //use this for initialization
      void Start ()
      {
    
      }
    
      //Update is called once per frame
      void Update ()
      {
    
      }
    
      void MoveObject ()
      {
      
      }
    }

    You've now declared a brand-new function, as simple as that.

  2. Next, add the following line of code that will make it move positively along the x axis (to the right) by two units:

    Void MoveObject ()
    {
      gameObject.transform.Translate(2.0f, 0.0f, 0.0f);
    }

    The parentheses at the end of this line tell us that a function is...