- Home /
Displaying Score on screen
I need a script that when I hit a game object my score increase by 2 and is displayed on the screen. I have been trying to make it work myself, but I haven't made it work.
Thanks.
Comment
Answer by getyour411 · Jan 13, 2014 at 02:47 AM
You didn't post what you did have but something like
OnTrigger/Collider () {
playerScore += 2;
}
OnGUI {
GUI.Box(new Rect(10,10,100,30),playerScore.ToString());
}
var scoreText = "Score: 0";
var score : int = 0;
unction OnCollisionEnter(boom:Collision)
{
if(boom.gameObject.tag==("Clown"))
{
Destroy(gameObject);
score +=2;
scoreText = "Score : " +score;
}
}
function OnGUI()
{
GUI.Box(new Rect (10,10,100,20),scoreText);
}
This is the code that I have. Every time the gameObject collides with an gameObject with the tag "Clown" it just shows " Score: 0 " and it does not add by 2. I need it every time the gameObject collides, the score adds by 2.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How To Stop Destroyer From Destroying? 2 Answers
Guitext for score over time. 2 Answers
Score board acting funny 1 Answer