- Home /
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 () {
}
Answer by aldonaletto · Sep 19, 2011 at 03:51 AM
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.
Your answer
Follow this Question
Related Questions
How to save score for survival time? 1 Answer
Multiplayer ScoreBoard not Updating Correctly 0 Answers
saving scores and let other user to view it 2 Answers
Scoring System 3 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers