I just tried each and everything I knew, but my program wont work. It shows the
“You Lose” screen just when it decreases 1 NRG point. HELP!!!
var EnergyLoss = 1;
var EnergyLossTiming = 10;
var LastEnergyLossTime = 0;
var Energy = 100;
function Update(){
if((Time.time-LastEnergyLossTime)>EnergyLossTiming)
{
HealthConfidenceNRG();
LastEnergyLossTime = Time.time;
}
}
function HealthConfidenceNRG(){
Energy -= EnergyLoss;
if (Energy == -1);
{
Time.timeScale = 0;
LostTheGame = true;}
Debug.Log("Energy reduced to" + Energy);}
function OnGUI()
{
GUI.skin = newSkin;
GUI.Box (new Rect (0,1,100,30), "Energy" + ":" + Energy.ToString());
GUI.Box (new Rect (100,1,100,30), "Health" + ":" + Health.ToString());
GUI.Box (new Rect (200,1,100,30), "Confidence" + ":" + Confidence.ToString());
if (LostTheGame){
GUI.Box(Rect(Screen.width /2 - 100,Screen.height /2 - 100,250,200), "You Lose");
//Make Main Menu button
if(GUI.Button(Rect(Screen.width /2 - 100,Screen.height /2 - 50,250,50), "Main Menu")){
Application.LoadLevel(MenuSceneName);
}
//Make Retry button
if(GUI.Button(Rect(Screen.width /2 - 100,Screen.height /2 ,250,50), "Retry")){Application.LoadLevel(CurrentSceneName);}
}
}