- Home /
spawn prefabs in loop after collision
hi..im currently new at unity codes..can anyone help me about this problem..the thing is that i want a snowball prefab to respawn after collision(when the character hits a visible collider or whatever that triggers the collision) in a certain amount of loop like 10 snowballs..and it should have a gap like 1 sec per snowbal..
i did my research but i cant find any solution for my problem..i hope anyone can get my point.. tnx a lot in advance..
Are you saying you want to have snowballs respawn according to a rate of fire?
Answer by AnXgotta · Aug 12, 2012 at 04:19 PM
You could use a coroutine:
C#:
public IEnumerator spawnSnowball(){
for(int i = 0; i < numSnowballs; i++){
// do snowball spawn
yield return new WaitForSeconds(timeToWaitBetweenSpawns);
}
}
pubic void OnTriggerEnter(Collider c){
StartCoroutine("spawnSnoball");
}
You would have to customize to fit your situation but I think a coroutine is what you need.
Your answer
![](https://koobas.hobune.stream/wayback/20220613075345im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why does audio get out of sync with multiple loops playing? 1 Answer
Sequential Coroutines sometimes halt 1 Answer
My loop isn't working??? (C#) (Need help please) 1 Answer
Problem with looping concatenation with custom class 1 Answer
Lerping & OnCollisionEnter - how do i lerp without update?? 1 Answer