Hello guys, I am working on make up a simple scoring script. But I have come up with an issue with add to a score once an “enemy” has been destroyed or removed form the game world
private int scoreKeeper;
public int enemyNumber;
// Use this for initialization
void Start () {
scoreKeeper = 0;
}
void Update () {
enemyNumber = GameObject.FindGameObjectsWithTag ("enemy").Length;
if (enemyNumber <= 1) {
scoreKeeper += 10;
}
}
void OnGUI () {
GUI.Button (new Rect (10, 60, 100, 45), string.Format("{0}", scoreKeeper));
}
This is what I came up with, but as I am sure you guys know, this does not work. When there is one enemy left the game updates the score by 10 each update so it goes up pretty fast!
I thought that something like
void Update () {
enemyNumber = GameObject.FindGameObjectsWithTag ("enemy").Length;
if (enemyNumber -= 1) {
scoreKeeper += 10;
}
}
would work add in the - but it comes up with an error.
I was trying to make it so each time an enemy was destroyed it added 10 to a number.
Thanks for any help guys!