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.

2 Answers

2

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.

Use ontriggerenter