Search Unity

Character transfer between levels

Discussion in '2D' started by CrocodilusCZ, Oct 2, 2019.

  1. CrocodilusCZ

    CrocodilusCZ

    Joined:
    Sep 26, 2019
    Posts:
    2
    Hello, First of all, I apologize for my bad English.

    I'm a beginner, but I haven't been able to deal with this problem for days.


    I have a character screen to set the face, body color:


    Everything works on this screen. If the character falls below y <- 10 it will appear again on SpawnPoint.


    If I click the START button, level1 is loaded:


    Unfortunately, neither respawn nor subtraction of health is working on this new screen.

    I have been worried about this for a long time and I still don't know how to do it, I would like to ask for advice. Thank you
     

    Attached Files:

  2. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    You can store the healths value somewhere and change it after the new level was loaded.
    1. PlayerPrefs
    https://docs.unity3d.com/ScriptReference/PlayerPrefs.SetInt.html
    then befor you will load the new level:
    PlayerPrefs.SetInt ("health", currentHealth);
    and in the next loaded level:
    void Start() {
    playersHealth = PlayerPrefs.GetInt ("health");
    }

    2. Json
    here was one good tutorial


    3. something other

    You can keep an gameobject for the next level with dontdestroyonload
    https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html
     
  3. CrocodilusCZ

    CrocodilusCZ

    Joined:
    Sep 26, 2019
    Posts:
    2
    Thank you for your advice, I think it is time to put up with the fact that I will not finish my first project right away :)