public void StartCustomMode(ModeGoal goal, BagType bagtype, int width, bool overtuned) { PersistantVars.pVars.PlaySound(SoundEffects.MENU_SELECT); PersistantVars.pVars.goal = goal; PersistantVars.pVars.bagType = bagtype; PersistantVars.pVars.width = width; PersistantVars.pVars.overtuned = overtuned; SceneManager.LoadScene("MainGameScene"); //Start game. }
//Awake is like Start, but even earlier. void Awake() { //If this is the first copy of PersistantVars, set up a self-reference that other objects can use. Otherwise, destroy self to ensure there is only one. if (pVars == null) { pVars = this; } else //if (pVars != this) //The sample code I found has the extra "if" on the "else", but is it really necessary...? { Destroy(gameObject); return; } //Initialize persistant vars NUM_CURSES = Enum.GetNames(typeof(Curse)).Length; forcedCurses = new bool[NUM_CURSES]; enableCurseGeneration = true; difficulty = 1; goal = ModeGoal.SURVIVE; bagType = BagType.CURSED; width = 10; overtuned = false; ref_Audio = GetComponent <AudioSource>(); //Set pseudo-global audio volume if (PlayerPrefs.HasKey("volume")) { ref_Audio.volume = PlayerPrefs.GetFloat("volume"); } else { ref_Audio.volume = DEFAULT_VOLUME; } InitHighScores(); //Don't destroy on load. That's kinda what "persistant" means. DontDestroyOnLoad(gameObject); }