How to instantiate a Prefab in a random range in 5 secs ?

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

17050-giochi-puzzle-online-cannon-bods.jpg

How can i do?
Thanks in advance :slight_smile:

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;
    }