Does anyone know how to make a script wait, e.x.
Im instantiating alot(10) cubes, but i want them to instantiate with an interval of 1 sec.
Im thinking the WaitForSeconds will work, but dont know how to use it properly.
This is my script
using UnityEngine;
using System.Collections;
public class SpawnPlayer : MonoBehaviour {
public Transform cubie;
void Start(){
for(int i = 0; i < 10; i++){
Instantiate(cubie,new Vector3(i * 2.0f, 0, 0), Quaternion.identity);
}
}
}
I dont want straight answers, would rather like tips, and ideas.
Allready tried that, gives me this error:
“The body of SpawnPlayer.Update()' cannot be an iterator block because void’ is not an iterator interface type”
using UnityEngine;
using System.Collections;
public class SpawnPlayer : MonoBehaviour
{
public float WaitingTime = 6f;
public Transform cubie;
IEnumerator CreateCubes()
{
for(int i = 0; i < 10; i++)
{
Instantiate(cubie,new Vector3(i * 2.0f, 0, 0), Quaternion.identity);
yield return new WaitForSeconds(WaitingTime);
}
}
}
You can also spawn in the Update instead, keeping track of the time since you last created a cube.
When that time is >= Time Between Spawns, then reset it.