0

I'm having trouble saving and loading a scene. I have this code:

public void LoadData(Data data)
{
    this.sceneName = data.sceneName;
    SceneManager.LoadScene(sceneName);
    this.level = data.level;
}

public void SaveData(ref Data data)
{
    data.sceneName = SceneManager.GetActiveScene().name;
    data.level = this.level;
}

and when I have a line in my code that contains "SceneManager.LoadScene(sceneName);" is the player's level, which he writes at the beginning of the code as follows `public int level = 1; public int health = 100; I'm signing up incorrectly. The Player level object changes, but when I want to get it using player.level; it shows me level "1" even though it is equal to 2

All I know is that the problem occurs by loading the scene. When I remove the line SceneManager.LoadScene(sceneName); level updates normally

JaQubiaQ
  • 1
  • 2
  • Would this solve your underlying problem? https://stackoverflow.com/questions/32306704/how-to-pass-data-and-references-between-scenes-in-unity – derHugo Jan 07 '23 at 22:31

0 Answers0