You can use the `PlayerPrefs` class to store values between sessions. If you only want to store it between levels, you can use the `DontDestroyOnLoad` method.
player
var Scores : float = 0.0;
var skin : GUISkin;
function Start ()
{
//it will automotically load the last value.
Scores = PlayerPrefs.GetFloat("Coin");
}
function OnGUI ()
{
GUI.skin = skin;
GUI.Label (Rect(330, 18, 100, 30), "Scores: " + Scores);
}
function OnTriggerEnter (other:Collider)
{
if (other.tag == "Coin")
{
var coin = other.GetComponent(coinScript);
AddScore(coin.value);
Destroy(other.gameObject);
}
//it will save automatically on save points.
if (other.tag == "SavePoint")
{
//it will automatically check if this value is more then the previous
if (PlayerPrefs.GetFloat("Coin")<Scores)
{
PlayerPrefs.SetFloat("Coin", Scores);
}
}
}
function AddScore (value : float)
{
Scores += value;
}
coin
var value : float = 1.0;
var animation : Animation;
player
var Scores : float = 0.0;
var skin : GUISkin;
function Start ()
{
//it will automotically load the last value.
Scores = PlayerPrefs.GetFloat("Coin");
}
function OnGUI ()
{
GUI.skin = skin;
GUI.Label (Rect(330, 18, 100, 30), "Scores: " + Scores);
}
function OnTriggerEnter (other:Collider)
{
if (other.tag == "Coin")
{
var coin = other.GetComponent(coinScript);
AddScore(coin.value);
Destroy(other.gameObject);
}
//it will save automatically on save points.
if (other.tag == "SavePoint")
{
//it will automatically check if this value is more then the previous
if (PlayerPrefs.GetFloat("Coin")<Scores)
{
PlayerPrefs.SetFloat("Coin", Scores);
}
}
}
function AddScore (value : float)
{
Scores += value;
}
coin
var value : float = 1.0;
var animation : Animation;
…
bla bla bla
i think that you know how to do.