x


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 () {
}
more ▼

asked Sep 19 '11 at 03:25 AM

Beta_Artist gravatar image

Beta_Artist
1 14 15 15

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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;
   }
}

more ▼

answered Sep 19 '11 at 03:51 AM

aldonaletto gravatar image

aldonaletto
41.4k 16 42 197

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.

Dec 12 '12 at 05:37 PM himanshu619
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5076
x798
x273
x29
x25

asked: Sep 19 '11 at 03:25 AM

Seen: 2939 times

Last Updated: Dec 12 '12 at 05:37 PM