- Home /
Static Variable not working correctly
Hi!
I'm working on a script that allows the player to, once 25 seconds have gone up, change to the next level, and while the level changes have a fade out. I borrowed someone else's fade out script, and i cant seem to get that script to recognize that a variable is true. Any ideas?
This is the First Script
#pragma strict
static var busWait : boolean = false;
static var levelChange : boolean = false;
function Start () {
yield WaitForSeconds (20);
busWait = true;
}
function Update () {
if(busWait == true) {
Debug.Log ("Ready to Click");
if(Input.GetMouseButton(0)) {
levelChange = true;
Debug.Log ("Mouse Was Clicked");
}
}
}
And this is the FadeOut
private var fadeIn : boolean = true; // false for fade out
private var color : Color = Color.black;
private var timer : float = 0;
function FadeIn()
{
timer = fadeTime;
fadeIn = true;
}
function FadeOut()
{
timer = fadeTime;
fadeIn = false;
}
function Start() {
if(BusWait.levelChange == true) {
Debug.Log("Level Change Complete");
FadeOut();
yield WaitForSeconds (5);
Application.LoadLevel("busIntro");
}
}
function OnGUI()
{
if (fadeIn)
{
color.a = timer / fadeTime;
}
else
{
color.a = 1 - (timer / fadeTime);
}
GUI.color = color;
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), blackScreen);
}
function Update()
{
timer -= Time.deltaTime;
if (timer <= 0)
{
timer = 0;
}
}
I assume you are talking about the variable busWait and checking it in the Start() method?
Are you sure the Start() of the second script is called after 20 seconds and not when you start the scene?
Actually i'm trying to get the FadeOut script to recognize if the levelChange variable is true or false. For some reason it doesnt want to acknowledge that the variable is true. Everything else works, just that part doesnt
You're checking BusWait.levelChange in the Start function of FadeOut script. How are you creating the FadeOut component? Are you trying to creating a FadeOut component after BusWait.levelChange is true or make the check be done every frame via the Update function?
I'm making the FadeOut component after BusWait.levelChange is true, yes