- Home /
spawn prefab in loop after collision?
hi..im new here in unity..can anyone help me about this problem..the thing is that i want a prefab like snowball to spawn after the character hits a invisible collider(or whatever that triggers the collision) in a loop like 15 snow ball prefab..and the snow should have a gap after spawning like 1 second per snowballs..
i did my research about this problem but i cant find any solution.. i hope anyone can get my point.. tnx a lot in advance...
Answer by speedything · Aug 08, 2012 at 02:52 PM
Start Coroutine when collision is detected
Set count to 0
Enter "While count < 15 loop"
Instantiate prefab
Add one to count
Wait for one second
Answer by IndieScapeGames · Aug 08, 2012 at 02:57 PM
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public GameObject prefab;
void OnCollisionEnter() {
int count = 0;
while(count < 15) {
Instantiate(prefab, position, Quaternion.identity) as GameObject;
count++;
waitMethod();
}
}
IENumerator waitMethod() {
yield return new WaitForSeconds(1);
}
}
This code is untested, but should give you a GREAT head start.
hi there..tnx for the head start but there is something wrong in the codes something like only assignment, decrements ,increment and new object can be used as statement..any help here..tnx again in advance..
Change "wait$$anonymous$$ethod();" to "StartCoroutine(wait$$anonymous$$ethod());"
Your answer
Follow this Question
Related Questions
Can the animation editor create local rotational data? 3 Answers
Unity Water Help 2 Answers
Joining separated prefabs to one source prefab 0 Answers
Scaling down dynamically created objects 1 Answer
Prefab linking 3 Answers