Hello,
I have troubles carrying on my global vars trough scenes. I change the language setting in my menu ingame, then i launch a scene via a new game button and the setting is gone.
Here is my GlobalVar class:
using UnityEngine;
using System.Collections;
public enum GameDifficulty
{
Easy,
Medium,
Hard
}
;
public enum Language
{
english,
french
}
;
public class GlobalVars : Singleton<GlobalVars> {
protected GlobalVars () {} // guarantee this will be always a singleton only - can't use the constructor!
public GameDifficulty difficulty = GameDifficulty.Medium;
public Language language = Language.english;
void awake()
{
DontDestroyOnLoad(gameObject);
}
}
I also have a script in my project which contain a singleton class (used for an audio manager). Maybe it have something to do with this. Both are codes i didn’t wrote myself and I’m so lost! Here it is:
using UnityEngine;
using System.Collections;
public class Singleton<T> : MonoBehaviour where T : MonoBehaviour {
protected static T instance;
//Returns the instance of this singleton
public static T Instance {
get {
if (instance == null) {
instance = (T)FindObjectOfType(typeof(T));
if (instance == null) {
GameObject container = new GameObject();
container.name = typeof(T)+"Container";
instance = (T)container.AddComponent(typeof(T));
}
}
return instance;
}
}
}
Can you please tell me where i’m wrong?