0
\$\begingroup\$

In my game, I'd like to stop counting points when the player's y is -4. When the pink and red balls fall off the Plane the player gets points. But it seems a bit strange to be able to collect points after the player dies.

The game is over, but the points are still pouring in.

This is the code for the player:

     if (transform.position.y < -4)
    {
       Destroy(gameObject);
       gameManager.GameOver();
    }

And in the GameManager.cs I have this:

   public bool isGameActive;

   public void UpdateScore(int scoreToAdd)
   {
      score += scoreToAdd;
      scoreText.text = "POENG: " + score;
   }

   public void GameOver()
   {
      isGameActive = false;
      restartButton.gameObject.SetActive(true);
      gameOverText.gameObject.SetActive(true);
   }

And this is the code for adding points when the enemies fall over the edge:

    if (transform.position.y < -4)
    {
       Destroy(gameObject);
       gameManager.UpdateScore(pointValue);
    }

How can I make the game stop counting points when the player dies?

\$\endgroup\$
1
\$\begingroup\$

In the updatescore method you simply ask, whether isGameActive is true or not.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks a lot! It works like a charm when doing this, as suggested: if (isGameActive == true) { score += scoreToAdd; scoreText.text = "POENG: " + score; } \$\endgroup\$
    – Senseless
    Nov 9 '19 at 15:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .