Book Image

Unity 5.x Game Development Blueprints

By : John P. Doran
Book Image

Unity 5.x Game Development Blueprints

By: John P. Doran

Overview of this book

<p>This book will help you to create exciting and interactive games from scratch with the Unity game development platform. We will build 7-8 action-packed games of different difficulty levels, and we’ll show you how to leverage the intuitive workflow tools and state of the art Unity rendering engine to build and deploy mobile desktop as well as console games.</p> <p>Through this book, you’ll develop a complete skillset with the Unity toolset. Using the powerful C# language, we’ll create game-specific characters and game environments. Each project will focus on key Unity features as well as game strategy development. This book is the ideal guide to help your transition from an application developer to a full-fledged Unity game developer</p>
Table of Contents (19 chapters)
Unity 5.x Game Development Blueprints
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Preface
Index

Game start and end behaviours


Now, we don't want a game to automatically start as soon as we hit the play button. We want to give the player a chance to tap and then start spawning the obstacles. To do this, we'll create our own components that we will add and remove dynamically to contain this additional behavior.

  1. Go to the Project tab, open up the Scripts folder, and create a new script named GameStartBehaviour. Open it up and use the following code:

    using UnityEngine;
    
    public class GameStartBehaviour : MonoBehaviour {
    
        /// <summary>
        /// a reference to the player object.
        /// </summary>
        private GameObject player;
    
        // Use this for initialization
        void Start ()
        {
            player = GameObject.Find("Plane");
            player.GetComponent<Rigidbody2D>().isKinematic = true;
        }
        
        // Update is called once per frame
        void Update ()
        {
            // Start the game
            if ((Input.GetKeyUp("space") || Input.GetMouseButtonDown(0)))
            {
    ...