On this scene, I only have 2 game objects. 1 empty object with a spawner script, and 1 with sprite renderers, colliders, and etc for the map.
The spawner script instantiates enemy ships on each spawn points at the start function.
Map:
My spawn points are those white circles outside the star.
What should happen:
As you can see, the enemy ships are on their corresponding position.
The enemy ships contains a sprite renderer, polygon collider, and a rigidbody.
What happens often:
At the bottom left, you see some enemy ships spawning at 0,0 for some reason I can’t figure out…
Spawn Script (simplified) (yeah, bug still occurs with this script):
public SpawnPoints top;
public GameObject t1Enemy;
public float spawnRate;
void Start () {
StartCoroutine(Spawn());
}
IEnumerator Spawn () {
while (true) {
T1Spawn();
yield return new WaitForSeconds(spawnRate);
}
}
void T1Spawn () {
Instantiate(t1Enemy, top.one.position, top.one.rotation);
Instantiate(t1Enemy, top.two.position, top.two.rotation);
Instantiate(t1Enemy, top.three.position, top.three.rotation);
Instantiate(t1Enemy, top.four.position, top.four.rotation);
Instantiate(t1Enemy, top.five.position, top.five.rotation);
Instantiate(t1Enemy, top.six.position, top.six.rotation);
Instantiate(t1Enemy, top.seven.position, top.seven.rotation);
Instantiate(t1Enemy, top.eight.position, top.eight.rotation);
Instantiate(t1Enemy, top.nine.position, top.nine.rotation);
}
TL;DR: Game Objects are spawning at 0,0 occasionally even if I stated on the script to spawn them at the specific spawn points.
What am I doing wrong?