Point System and pickup

Hi I am wondering how you could create a simple point system using a GUI and picking up an object.


The simplest answer I can think of is:

  1. Make the score a public static variable so that it can be accessed from anywhere (not necessarily the best choice in terms of software design, but nevertheless probably the most straightforward solution).

  2. Give the items to be picked up colliders, and check the 'is trigger' checkbox for them in the inspector.

  3. Add a script to the player object or the item objects that includes an OnTriggerEnter() function. In this function, check if the other object has the right name/tag/etc. (if necessary), and if it does, increase the score as appropriate and destroy the item object.

  4. Create a script with an OnGUI() function, attach it to some game object or other, and display the score using GUI/GUILayout.Label().


This is the main script i have for my score system or point system. Name this script Score.


-create a sphere.

-add Sphere Collider on sphere

-tag the Sphere as Coin

-add this javascript to your character and your ready to go.

You have a pick up system with score on your screen(GUI).

Thank you.

var score = 0;
var scoreText = "Score: 0";
var mySkin : GUISkin;

function OnTriggerEnter( other : Collider ) {
    Debug.Log("OnTriggerEnter() was called");
    if (other.tag == "Coin") {
        Debug.Log("Other object is a coin");
        score += 1;
        scoreText = "Score: " + score;
        Debug.Log("Score is now " + score);

function OnGUI () {
    GUI.skin = mySkin;
    GUI.Label (Rect (10, 10, 500, 200), scoreText.ToString()); }