I am trying to make a text counter UI that shows the # of remaining enemies in the scene.
It would look something like:
Baddies Alive: 12
I’ve got it mostly working (kill a baddie and it takes -1 from the counter) my issue is, how do I let the game know how many baddies are in fact alive at the start of the scene? As of right now, the counter starts at 0 and goes into the negative after each kill. Any ideas?
Hi, how do you set the number of enemies in your scene?
Generally you could make a variable (e.g. baddy_count) and set it to the number you like. You can use this variable for spawning the enemies and also to display the value in the counter at the beginning of the scene. Then, after killing a baddie you reduce the counter by 1.
Hello, and thanks for responding.
I am in the process of trying what you mentioned, the enemies aren’t spawned but rather placed by hand (I am using the Platformer Tutorial) and I can’t seem to understand how the variable will know how many enemies have been placed initially without some other component. I’m headed back to my lab for more experimenting on the matter.
There is an expression “SceneInstancesCount()” which you can populate with any object and it’ll give you the number of them that exists. Just put that into a ToString() and update your text object to display that via events.