Hello, I built the timer which is triggered by an event in my scene, counts down and as soon as it reaches “0” my player dies - Time.timeScale = 0.0, and appears gui.window with the button “restart”. The button behaves this way, if pushed, it resets all the static variables and loads the same level as I play. But the problem is, right after the “resetting” I spaw in the beginning and immediately see the window of “Game Over” again, with the button “reset” and everything that was explained above. But at this time I push “reset” (its already second time) - it resets everything, seems like… So Im gonna show the GUI script, timer script and the death().
---------TIMER----------
var myTimer: float = 10.0;
var timerOutput: GUIText;
static var timeIsUp = false;
function Update()
{
if(myTimer > 0 && pickUpSample.sampleCntr == 1)
{
myTimer -= Time.deltaTime;
var seconds: int = myTimer % 60; // calculate the seconds
var minutes: int = myTimer / 60; // calculate the minutes
timerOutput.text = minutes + ":" + seconds;
}
if(myTimer <= 0)
{
Debug.Log("Game Over!");
timeIsUp = true;
}
}
---------GUI box--------
function OnGUI()
{
if(death.isDead == true)
{
GUI.Box (Rect (291,250,240,115), "
You are dead", styleWindowObjectives);
if(GUI.Button (Rect (428,325,75,20), "restart", styleBtn))
{
Debug.Log("restart");
resetTheVariables();
Time.timeScale = 1.0;
death.isDead = false;
Application.LoadLevel("laboratoryG");
}
if(GUI.Button (Rect (320,325,75,20), "menu", styleBtn))
{
resetTheVariables();
Application.LoadLevel("mainMenu");
}
//GUI.Label (Rect (260,300,242,100), " It was level1");
}
if(isPaused)
{
GUI.Box (Rect (291,250,240,115), "
Pause", styleWindowObjectives);
GUI.Label (Rect (260,280,242,100), "
Press ESC to go back", styleTxt);
}
}
function resetTheVariables()
{
boxGlow.boxTextReady = false;
boxLidOpen.boxIsOpen = false;
death.isDead = false;
diskInsert.diskIsInserted = false;
doorExitBOpen1.doorExitBiSOpen = false;
doorExitEOpen.doorExitEiSOpen = false;
doorLockerOpen.lockerReady = false;
timer.timeIsUp = false;
input1Respond.inputTextEnable = false;
input1Respond.inputReady = false;
inputExit.inputExitText = false;
inputExit.inputExitRespond = false;
keyLockerOpen.keyLockerReady = false;
readerGlow.diskReaderText = false;
stopHintSuit.suitTextIsReady = false;
triggerS.sTrigger = false;
triggerS.sampleTextHintEnable = false;
triggerE.eTriggerReady = false;
triggerKL.lkTriggerReady = false;
triggerLD.ldTriggerReady = false;
pickUpKey.keyCntr = 0;
pickUpSuit.suitCntr = 0;
diskPickUp.diskCntr = 0;
pickUpSample.sampleCntr = 0;
}
---------death----------
var Camera: GameObject;
static var isDead = false;
function Update ()
{
death();
}
function death()
{
if(timer.timeIsUp == true)
{
Time.timeScale = 0.0;
Camera.GetComponent(Tonemapping).enabled = true;
//Camera.GetComponent(Tonemapping).exposure -= 1;
isDead = true;
}
}