Need help with creating a randomized enemy spawner

Link to my game editor PlayCanvas | HTML5 Game Engine
Link to my game PlayCanvas | HTML5 Game Engine
Hello! I’m creating a top-down shooter, I’m trying to script an Enemy Spawner in the game that randomizes the enemy’s spawn point so multiple enemy’s spawn at different locations.
I ran into a problem with the script. it only spawns two enemy’s and then stops, I don’t know what to do now to get it to spawn multiple enemy’s in different locations in the game. Could you check the script to see if it’s correct or help in any other way? Thank You! I’ve attached the whole script along with a part of the script that I need to fix.


Screenshot 2022-12-07 104756

@Bradley_Pelletier In this projects code I have done something similar in the enemy-manager.js script. Maybe this will help.

Halloween Jaunt - Remix2 | Editor (playcanvas.com)

Thank you, I’ll try it out!

Hi @Bradley_Pelletier! I notice your spawn code is outside your spawn statement. This is why it’s spawning continuously. I guess line 19 should be after line 29 (but before current line 30).

1 Like