I’m not really sure that if it is in same scene or if scene changes and you need to save it.
But both ways you need to make game object where to put your scores.
if scene does not change:
First create a empty game object to assign the following script
ScoreScript:
var score = 0;
function OnGUI () {
GUI.Label(Rect(10, 10, 200, 100), "Score: " + score.ToString());
}
Add this to player and then int “scoreObject” you need to assign empty game object you just made
PlayerScript:
var score = 0;
var scoreScript : ScoreScript;
var scoreObject : GameObject;
function Start () {
//accessing from this script to other script on other object
scoreScript = scoreObject.GetComponent("ScoreScript");
}
function OnTriggerEnter( other : Collider ) {
if (other.tag == "Coin")
{
score += 1;
scoreScript.score += 1;
Destroy(other.gameObject);
}
}