Setting up a score system to keep track of the score. How should I do this?

Hi there,

I am creating a endless runner, I’m almost done but require to add a score system, in which each item I jump I get one point… I’ve been looking for the past two days for a tutorial on making system to keep track of Points/Score and I haven’t found anything that works with the new unity UI.

Basically I think (and hope) it would be set out that as my player collides with an invisible object above the item I am jumping over, I get one point. I’d also like to a highscore system, if you guys know much about all that.

I am hoping, someone here can direct me to a tutorial in C# (Or easily convertible) or send some sample script with the set-up explained…

Sorry for asking for help without even having some script, but I’m kind of clueless how to start.

Thanks!

Do you mean, with a database, so you can get the value for another time?
Otherwise, implementation of a score variable with the unity UI is pretty straight forward:

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class ClickScore : MonoBehaviour {
    Text text;
    int score = 0;

    void Start () {
        text = transform.Find("Text").GetComponent<Text>();
    }
   
    void Update () {
        if (Input.GetMouseButtonDown(0)) {
            score++;
            text.text = "SCORE: "+score;
        }
    }
}

Example enclosed as unityPackage. I used “clicking” to get a score, rather than jumping, for brevity’s sake.

1889171–121560–ClickScore.unitypackage (7.61 KB)

Hi there, Thanks for the reply!

I’m still unsure on about how I’d make a script as when my player collides with an object, it adds to the score… I understand I’d need two scripts?

void OnCollisionEnter(Collision col){
if(col.gameObject.tag == "object tag"){
score++;
}

}

you could make score “public static” to access in any other script of game. this function goes onto Player…

anyway google is ur best bet…search “unity collision scripting”

May I ask, how exactly would I make the score a ‘Public Static’? I’m guessing thats how I’d link these two scripts to work with each other?

You are far from “almost done” if you don’t understand that.

http://unity3d.com/learn/documentation

There are a lot of tutorial series on youtube that cover this sort of thing.
I think my first score system was inspired by this series:

Josh it sounds like you should do some scripting tutorials, learning the concepts behind programming would definitely make development easier for you.

That being said, specifically what you’re looking for is the OnCollisionEnter event, as mubashar pointed out.

I whipped up a quick example:

1890040–121626–CollisionScore.unitypackage (25.5 KB)