Sunday, March 9, 2014

Scene Manager Script

// Scene Manager Script

// Inspector Variables
var gameTime :float = 60;
static var score : int = 0;
static var lives : int = 3;
var labelRight : float = 100;

// Private Variables
function Start()
{
InvokeRepeating("CountDown",1.0,1.0);
}
//Game Loop
function Update ()
{
if(lives <0)
{
Application.LoadLevel("ScreenLose");
// reset player's life
lives = 3;
//display score in lose screen
PlayerPrefs.SetInt("SCORE",score);
}

if(gameTime <= 0)
{
Application.LoadLevel("ScreenWin");
lives = 3;
PlayerPrefs.SetInt("SCORE",score);
}

// Print Score
print("Score:"+score);
}

function AddScore() // everytime this function is call add +1 to the score
{
score+=1;
}

function SubtractLife()
{
lives -=1;
}

function CountDown()
{
if (--gameTime ==0)
{
CancelInvoke("CountDown");
}

}
// GUI label
function OnGUI ()
{
GUI.Label(Rect(10,10,100,20),"Score:"+score); //(left,top,width,height)
GUI.Label(Rect(10,25,100,35),"Live:"+ lives);
GUI.Label(Rect(Screen.width - labelRight,10,100,20), "Counter:"+ gameTime);
}

No comments:

Post a Comment