Hallo everyone, i just want to instantiate a prefab every 5 seconds, y position = 0 x position = Random.Range (-10;10)
As in this image my prefab will be the parachutist
How can i do?
Thanks in advance
Hallo everyone, i just want to instantiate a prefab every 5 seconds, y position = 0 x position = Random.Range (-10;10)
As in this image my prefab will be the parachutist
How can i do?
Thanks in advance
Or just use InvokeRepeating
I would use a coroutine to achieve that functionality. I recommend reading this link.
Here is what you could do:
private bool bCanCreateParachuter = true; // bool to stop the spawning
void Start()
{
StartCoroutine("CreateParachuter");
}
IEnumerator CreateParachuter()
{
while(bCanCreateParachuter)
{
Instantiate(prefab, new Vector3(Random.Range(-10,10), 0, 0), Quaternion.identity);
yield return new WaitForSeconds(5f);
yield return null;
}
yield return null;
}