- Home /
Death Counter dont work when changing scenes
Hello my death counter doesn't work when i'm changing scenes, i have done void Awake() { DontDestroyOnLoad(this.gameObject); } on my death counter script but it just starts with 0 when im changing scenes.
Answer by Chimer0s · Feb 15, 2019 at 07:48 AM
Set the count variable to static to keep it consistent across all scenes. i.e.
public static int deathCount;
The value will never be reset unless you reset it manually or you restart the exe.
Answer by AbubakrKhan · Feb 15, 2019 at 12:21 AM
Use PlayerPrefs, when you die use this:
PlayerPrefs.SetInt ("deathCount", PlayerPrefs.GetInt("deathCount") + 1);
and when changing scene call:
PlayerPrefs.GetInt("deathCount");
Your answer
Follow this Question
Related Questions
How do I stop my sprite from jumping in the air? 1 Answer
How to check if an object hits the ground hard enough then add explosive force around it (2D) 1 Answer
so I'm trying to make a 2D platform but the first animation i make is the only one that registers 0 Answers
Destroy a gameObject in the scene if instantiate the same gameObject 0 Answers