Hello, I am trying to make a puzzle game and I have a small little text to display when the use wins.
This first script is called WinScreen.js.
#pragma strict
private var screenX = Screen.width;
private var screenY = Screen.height;
var style:GUIStyle;
private var didWin = false;
var nextIcon:Texture;
var menuIcon:Texture;
function Start () {
}
function Update () {
}
function OnGUI(){
Debug.Log(didWin);
if (didWin){
GUI.Label(Rect(0,0,screenX, screenY), "WIN", style);
if (GUI.Button(Rect (screenX/1.5 , screenY/2 , screenX/10, screenY/10),nextIcon, style)){
Application.LoadLevel(Application.loadedLevel+1);
}else if (GUI.Button(Rect (screenX/4 , screenY/2, screenX/10, screenY/10),menuIcon, style)){
Application.LoadLevel("scene0");
}
}
}
function win(){
didWin = true;
Debug.Log(didWin);
}
from another script attached to the same gameObject, I have:
gameObject.GetComponent(WinScreen).win();
Sometimes, this script works, and a win screen is displayed. Other times however, it seems that changing the didWin variable to true does nothing and it stays false and no win screen is displayed.
How can I fix this?