- Home /
Maintain variable values while changing levels
How do I maintain the values of my variables when I am changing from one scene to the next? Like with character health, everything gets restarted, even when I use DontDestroyOnLoad(random script). What are some good techniques that I can use?
Answer by zannghast · Oct 19, 2010 at 02:17 AM
Have you tried creating a gameobject, attaching a controller script that manages player health and such on it, then calling DontDestroyOnLoad on the gameobject upon Awake like so:
using UnityEngine; using System.Collections;
public class example : MonoBehaviour {
void Awake() {
DontDestroyOnLoad(transform.gameObject);
}
}
Your answer
Follow this Question
Related Questions
Save Integer Values 1 Answer
changing variables values !! 1 Answer
How do I use an enum value as a variable? 3 Answers
can't change variable through other script 1 Answer
Variables and ranges in javascript 2 Answers