Hello! I am having some problems I did not anticipate with my current enemy spawning system. I have a 2D game and I'm using a coroutine with WaitForSeconds as interval between enemy spawning. The precision of this interval is very crucial to the gameplay experience and because I am well into the development and only noticed this problem now I am pretty worried to keep using my current system.
I made a test project with simplified version of my spawn system without any pooling or such things. In this test I am just instating square sprites that move slowly to right with an interval of 0.77 seconds. Here is the result:
![alt text][1]
[1]: /storage/temp/55989-spawntest.jpg
This test perfectly replicates the problem I am having. As you can see, the spawn interval is not precise. The spacing between the spawned squares varies quite a bit and I have no idea what is behind this problem. Here is the spawn code:
using UnityEngine;
using System.Collections;
public class Spawner : MonoBehaviour {
public GameObject squareObj;
private Vector3[] spawnPos;
void Start ()
{
spawnPos = new Vector3[3];
spawnPos [0] = new Vector3 (-10.0f, -2.0f, 0.0f);
spawnPos [1] = new Vector3 (-10.0f, 0.0f, 0.0f);
spawnPos [2] = new Vector3 (-10.0f, 2.0f, 0.0f);
StartCoroutine ("Spawn");
}
IEnumerator Spawn()
{
while(true)
{
Instantiate (squareObj, spawnPos [0], Quaternion.identity);
Instantiate (squareObj, spawnPos [1], Quaternion.identity);
Instantiate (squareObj, spawnPos [2], Quaternion.identity);
yield return new WaitForSeconds(0.77f);
}
}
}
If anyone has any insights on this I would be glad to hear about it, thanks!
↧