I had a meeting with Stuart in order to fix the enemy respawn issue, as it was very confusing and tricky to solve. Ultimately, we did manage to fix the issue but with a compromise being that now all the enemy have the same health. I would have liked to have the different enemies have different amounts of health associated with them however instead the challenge just comes from the different enemies each having different speeds. This new “finished” enemy script can be seen below.
With this script you can see on line 45 how I have the enemy spawn in a range of locations. I would have liked to have the enemies also able to spawn across a range along the Y axis, however I don’t know how to do this while avoiding having the enemy spawn on screen. In order to fix the issue with the respawn I had to set the health of the enemy in this script, and as all my enemy prefabs use the same script this meant they all had to have the same health assigned to them.
Another thing I added here is the respawn script, this is assigned to a UI text with a simple if statement. Essentially with this script the UI text is always in the centre of the screen, but when in play the text is left empty.
My Restart Script
Only when the player comes into contact with the enemy is the text then displayed. Finally, I added the if statement that resets the game when the player pushes the R key. I think this is a somewhat inelegant solution as the player can restart the game by pressing R at any time. Perhaps it would have been nice to add some kind of gate that only allows the player to restart the game when the test is active however I have no way of doing this.
I also had to add just a small update to my score script, which meant that the player score resets when they restart the game. Previously this score just kept climbing even when the player and enemy positions had been reset.
At this stage I am very nearly finished with the game. I have just a few tweaks and touches which can be seen in my final thoughts post.