- Home /
Instantiating from a list of gameobjects randomly, with different positions for each gameobject...
I have a list of 10 gameobject prefabs used as enemies and a chance to spawn a random one every time you take one footstep in any direction. It's very functional and efficient; however, the objects are really 2D sprites in 3D space, so they spawn unevenly as they're not all the same size, often being submerged in the ground or completely invisible as they are behind a wall. How could I have them spawning at set positions so they are all aligned with the front of the player?
Thanks in advance ^_^
You could either have a Vector3 array of possible spawns positions, or a more complex solution where you declare $$anonymous$$/max xyz values for a defined cube that things can spawn in, or multiple cubes for more complex environments, or use raycasting or Physics.OverlapCube(...Sphere, ...) to make sure things are not behind/inside walls, in the ground, etc.