Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Counter goes up even if player is dead, how to solve?

Discussion in 'Editor & General Support' started by vs298045, Feb 21, 2023.

  1. vs298045

    vs298045

    Joined:
    Mar 30, 2021
    Posts:
    6
    I started making my first game and it is a clone of flappy bird. The issue that i have is that even after i die, if it happens to pass trough the trigger, it still gets a point up, but i want it to stop as soon as the bird is dead. I know how to reference the bird but i dont know the code line to stop the counter from going up.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,954
    If the player is dead, don't move the counter up.

    If you have a reference to the player you can check if it has been destroyed.

    Code (csharp):
    1. if (PlayerReference)   // coerces it to a bool
    2. {
    3.   // increase score
    4. }
     
  3. vs298045

    vs298045

    Joined:
    Mar 30, 2021
    Posts:
    6
    the script with the code you wrote is within a prefab so i referenced the the movement script of my bird but it doesnt really reference the players birdsAlive bool
     

    Attached Files:

  4. vs298045

    vs298045

    Joined:
    Mar 30, 2021
    Posts:
    6
    I got it, its fine. I tried again now and realized i can reference birdsAlive with a public movement deathBird to reference the script and with the line deathBird.birdsAlive == true i solved it. If it is true then it should add a score if not, it shouldnt.