- Home /
Score Display?
I figured out how to count score on my game, but how do I display it using Javascript? I want it displayed in the upper left corner of the screen, also I need help with the counting a bit two. I used the tags thing, but it counts score whenever it collides with any thing, I'm assuming that its a new script change I haven't heard of, but help on that would be great, but if you can only solve the first part its ok, thats what I was looking for anyway. Here's my script (I hope I posted it right)
#pragma strict
static var score1 : int;
var Score = 0;
var bounceValue = 1;
function Update () {
Score = score1;
}
function OnTriggerEnter () {
if (gameObject.tag == "Ball");
{
score1 += bounceValue;
}
}
What do I add to my script?
Answer by doublemax · Sep 09, 2016 at 11:32 AM
As for the score display: For a quick-and-easy solution you can use OnGUI():
function OnGUI()
{
GUI.Label( Rect(25, 25, 100, 30), "Score: " + score1 );
}
For fancier stuff you the new UI system which takes more time and effort to setup and use: https://unity3d.com/learn/tutorials/topics/user-interface-ui
Regarding the collider: You're checking the tag of the gameobject itself which is of course always the same. But you need to check the tag of the object you collided with:
function OnTriggerEnter (other : Collider)
{
if (other.tag == "Ball");
{
score1 += bounceValue;
}
}
Your answer
Follow this Question
Related Questions
Reset score to 0 1 Answer
Why my score system not working? 1 Answer
New score each level 1 Answer
Trying to get my spawn manager to respond to the current score 1 Answer
How to create a HighScore using playerprefs based on passed time? 1 Answer