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.
Go to the Project tab, open up the
Scripts
folder, and create a new script namedGameStartBehaviour
. 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))) { ...