Unity Game Score Script

I’m making a game where by clicking the moving target your gain points. I’ve got in figured out a little but the code isn’t responding. What am I missing? What code will help me have the score total appear on screen? I’ve looked all over and other scripts have not work for my application.

Moving object Script:

var buck : int = 1;
var ScoreBoard : GUIText (ScoreBoard);

function OnMouseOver () {
   if (Input.GetMouseButtonDown(0)) 
   {
        ScoreBoard.text = ("Score: ") + buck;
   }
}

function Update () {
}

1 Answer

1

This code only sets the score text to buck when you press the left mouse button over the object to which the script is attached.

If you want to add 1 to buck when the object is clicked, you should modify this code:

var buck : int = 1;
var ScoreBoard : GUIText; // <- drag your GUIText here

function OnMouseOver () {
   if (Input.GetMouseButtonDown(0)){
        buck += 1;
        ScoreBoard.text = ("Score: ") + buck;
   }
}

The scoreboard will initiate from value zero, can you tell that how to carry the sore of first level to next level so that the new score should be added into it.

–