I got my score counter to show up on my GUI Text, yet when I switch to another object with the same script its resets the score to zero. What can i change or add to stop it from resetting?
var speed = 5;
var buck = 100;
var deer = 10;
private var score : int = 0;
var ScoreBoard: GUIText;
function Update () {
transform.position += Vector3.forward * Time.deltaTime * speed;
}
function OnMouseEnter () {
Debug.Log("Hit");
speed = 15;
deer += 10;
ScoreBoard.text = ("Score: ") + deer;
}
function OnMouseExit () {
Debug.Log("Safe");
speed = 5;
}
A static variable is created once at the program beginning, lives while the program is running and is unique: all script instances use the same variable. Non-static variables exist in each script instance and are independent of each other.