Create Simple Score System

Hi everyone! Sorry for making this question even that i found a lot of this.

I’ve been searching for a script and a simple tutorial how to create a simple score system.

I only want my player to catch some objects and the object disappear and give him points!

I’m really noob on the programming side!

Please, help me!

The best thing you can do is go to learnmesilly.com and do some tutorials. They will go over everything you need to.

Once you create the code to make the character catch a ball, use the following code to make the object vanish:

Destroy(*yourGameObject*);

For the scoring, make a script for your character with a public variable for the score. That way you can do this:

var Score : int = 0;

function ObjectCaught(theGameObject) {
    Destroy(theGameObject);
    Score++;
}

Add a tag to the collectible object, e.g. “food”.
Add a trigger collider to the collectible object.

If you want to use PlayerPrefs to keep your score, attach this script to the player:

void OnTriggerEnter (collider c) {
    if (c.transform.tag == "food") {
        Destroy(c.gameObject);
        addScore(your_score, 10); // add your own score
    }
}

void addScore(string variable_name, int points_to_add) {
    PlayerPrefs.SetInt(variable_name, PlayerPrefs.GetInt(variable_name) + points_to_add);
}

If you’re fine with a normal variable, attach this script:

int your_score = 0;

void OnTriggerEnter (collider c) {
     if (c.transform.tag == "food") {
         Destroy(c.gameObject);
         your_score += 10; // add your own score
     }
 }

Make sure that your player also has a trigger collider, and that at least one of the two (player or collectible) has a rigidbody attached.

Chek it It Easy and Simple And Free