/// <summary> /// Called when the ship is impacted. /// Decides whether to stop the game or just take a life from the player. /// </summary> private void OnShipImpacted() { numberOfLives -= 1; NumberOfLivesChanged?.Invoke(numberOfLives); if (numberOfLives > 0) { StartCoroutine(RestartLife()); } else { StopGame(); StartCoroutine(RestartGame()); } }
/// <summary> /// Start a new game: create a new ship, initialize the variables, & fire the necessary event handlers. /// </summary> private void StartGame() { GameObject shipGO = Instantiate(shipPrefab, Vector3.zero, Quaternion.identity); ship = shipGO.GetComponent <Ship>(); ship.Impacted += OnShipImpacted; numberOfLives = startingNumberOfLives; score = 0; gameIsInProgress = true; GameStarted?.Invoke(); NumberOfLivesChanged?.Invoke(numberOfLives); ScoreChanged?.Invoke(score); }