void Die() { AudioSource.PlayClipAtPoint(deathSound, transform.position); Powerup.SetSpeedBoost(false); Powerup.SetShield(false); lifeCounter.LoseLife(); // LoseLife handles the transitions and whatnot Destroy(gameObject); // Destroy the player GameObject }
private void LoseLife() { numberOfLives--; lifeCounter.LoseLife(); if (numberOfLives <= 0) { scoreText.gameObject.SetActive(false); gameOverGroup.SetActive(true); Text gameOverText = gameOverGroup.GetComponentInChildren <Text>(); gameOverText.text = string.Format(gameOverText.text, score); } }
void OnHitUnhealthyFood(Collision collision) { // Remove object Destroy(collision.gameObject); // Make player larger Vector3 scaleNew = transform.localScale + scaleIncrease; transform.localScale = scaleNew.magnitude < scaleMax.magnitude ? scaleNew : scaleMax; // Make player slower speed = Mathf.Max(speed - speedDecrease, speedMin); // Lose life int livesRemaining = lifeCounter.LoseLife(); if (livesRemaining == 0) { transform.localRotation = Quaternion.Euler(new Vector3(90, 0, 0)); tryAgainButton.SetActive(true); } }