How do I add score in my scene using GUIText?

I know this is a basic question and I apologize for that as well since I am new to Unity. I searched all the way out but ended up in vain while searching for score keeping, though I got few solutions here on this community while searching I am very much unclear on to how does adding score work and could it be saved while i am loading into the next scene.

Anybody could help solving the issue or provide some links/tutorials so that I would come to know better and clear regarding this would be great…

Thanks for your time.

To add at what syclamoth said, you’ll need a static var to keep it through scenes.

I have a similar Problem. I have a script but it doesn’t have a text to count the score. Here’s the script:

var PlayerScore = 0;
var ScoreText = “Score: 0”;
var MaxPoints : int;

function OnTriggerEnter( other : Collider ){
Debug.Log(“OnTriggerEnter() was called”);
if (other.tag == “point”){
Debug.Log(“Other object is a point”);
PlayerScore += 1;
ScoreText = "Score: " + PlayerScore;
Debug.Log("Score is now " + PlayerScore);
Destroy(other.gameObject);
}
}

function Update(){
if(PlayerScore > MaxPoints){
PlayerScore = 16;
print(“You Win!”);
ScoreText = “Score: 0”;
}
}
If you could help it would be great. Hopefully this can help you to vivek.

Hey All, here is your answer:
Note please put this script onto your “Player” only:
var score = 0; var scoreText = “Score: 0”; var mySkin : GUISkin;

function OnTriggerEnter(other : Collider ) {

if (other.tag == “Pickup”) { //Pickup is the tag please replace it with your pick-able item tag

    Debug.Log("Other object is a coin");

    score += 1;         //You can replace 1 with any integer this is you score 

    scoreText = "Score: " + score;

    Debug.Log("Score is now " + score);

    Destroy(other.gameObject);

}

}

function OnGUI () {

GUI.skin = mySkin;

GUI.Label (Rect (200, 10, 200, 400), scoreText.ToString()); 
}

Note:Mark this answer as correct, Thank you.