Мне неясно, что вы пытаетесь сделать здесь, но проблема определенно в том, что WaitAndPrint
никогда не заканчивается, у него есть while (true) {...}
, который не позволяет ему завершиться. Цикл не порождает объекты, WaitAndPrint
is.
То, что вы, вероятно, хотите, это:
public class FollowPath : MonoBehaviour
{
public int total;
public GameObject enemyAi;
public List<GameObject> enemy;
private IEnumerator coroutine;
// Start is called before the first frame update
void Start()
{
print("Starting " + Time.time);
StartCoroutine(addToPath(enemyAi));
}
private IEnumerator addToPath(GameObject ai) {
for (int i = 0; i < 1; i++)
{
yield return new WaitForSeconds(waitTime);
WaitAndPrint(2.0f, ai);
print("Before WaitAndPrint Finishes " + Time.time);
}
}
private void WaitAndPrint(float waitTime, GameObject ai)
{
print("WaitAndPrint " + Time.time);
enemy.Add(ai);
// Works for Object in Scene and Prefabs
Instantiate(enemy[enemy.Count - 1], new Vector3(1, 1, 1), Quaternion.identity);
}
}