O'Reilly logo

Unity 5.x Game Development Blueprints by John P. Doran

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required