- Home /
Enable variables in different scene *Answered*
I am creating an options tab at the menu of my game, and I want it to change things for a specific scene that I am not in yet.
I know how to do this in the current scene, but is there a way to change this stuff from a different scene?
Answer by whydoidoit · Mar 26, 2013 at 08:04 PM
You will need to store the values (perhaps in static variables or PlayerPrefs) and then have a script configure the loaded level in its Awake() function.
What exactly does a static variable do? Sorry for the noobish question
So a static belongs to the class itself, to the script if you like, not to the copy of the script attached to the GameObject. As such all scripts "share" this variable. The net effect of that is that it will live even when all of the scripts have been deleted between levels.
Settings.js
An GameObject has this script attached in Level1/Settings wherever
static var showBigEnemy : boolean;
function OnGUI()
{
showBigEnemy = GUILayout.Toggle(showBigEnemy, "Show Big Enemy");
}
Level2.js
function Awake()
{
if(Settings.showBigEnemy)
Instantiate(theReallyBigEnemy);
}
If I were using 3D text, would this work?
FastestButton.js
var Selectsound : AudioClip; var HoverSound : AudioClip; static var Quality : boolean = false;
function On$$anonymous$$ouseEnter () {
audio.PlayOneShot(HoverSound, 0.7);
transform.renderer.material.color = Color.gray;
}
function On$$anonymous$$ouseExit () {
transform.renderer.material.color = Color.white;
}
function On$$anonymous$$ouseDown () {
transform.renderer.material.color = Color.cyan;
audio.clip = Selectsound;
audio.Play();
Quality = true;
}
FastestQuality.js
function Awake() { if(FastestButton.Quality){ QualitySettings.currentLevel = QualityLevel.Fastest;
} }
Presu$$anonymous$$g something sets FastestButton.Quality earlier