Search Unity

Teleport and player life

Discussion in 'Getting Started' started by Flauros1, Jul 6, 2020.

  1. Flauros1

    Flauros1

    Joined:
    Jul 2, 2020
    Posts:
    22
    First of all sorry for my bad english

    Hi! If I make a change of scene when my player touchs something.. his points of life Will be 100/100 or the same life he was in the last scene?
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    If the player object is destroyed in the scene change, and you create a new one in the new scene, it is a brand new object with all default values for any variables on any attached scripts. If variables are declared as "static" then there is only 1 instance of that variable for all instances of the script, so that can be used for moving data between scenes. You can also set a GameObject to DontDestroyOnLoad so it doesn't get destroyed on scene change in the first place, meaning you'll have the same player object in the next scene instead of having to create a new one.