- Home /
Score Help (Im new)
Hi So I'm new to Unity and I have this simple score set up where when the laser collides with an enemy it adds to the score but it is not increasing as it hits. Also since my laser is an object that appears the GUI of score shows up multiple times when a laser is fired. So i was wondering how i could fix this and why the score isn't increasing.
Here is code on Laser:
private int Score = 0;
void AddScore () {
Score++;
}
public void OnGUI() {
GUI.Label(new Rect(20, 40, 100, 20), System.String.Format("Score: {0}", Score));
}
public void OnTriggerEnter(Collider collider) {
AddScore();
}
}
Answer by rutter · Mar 17, 2012 at 01:12 AM
If I'm not mistaken, it sounds like you're creating multiple laser objects? This isn't a problem, exactly, except if you've set it up so that each laser is tracking (and drawing) its own score, completely independent of the others.
If this is the case, you may want to track and draw the score from a different script attached to another object. You can use `GameObject.Find()` and `SendMessage()` to do this pretty easily.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
c# Quit button wont quit game 1 Answer
Highscore GUI not working properly help 0 Answers
Help! Why doesn't this work? GUI/Static vars Help! Javascript 1 Answer
GUI Array Help 1 Answer