- Home /
Question by
Gihotics · Jul 28, 2017 at 07:29 AM ·
instantiatedestroyspawncreaterandom spawn
How to spawn an object continually while floating vertically like a bubble
For example a bubble floating vertically is spawned to many more bubbles created to also move vertically. How do i make it happen so when i bust a bubble more bubbles would be created again and again.
Comment
Answer by ShadyProductions · Jul 28, 2017 at 07:45 AM
you probably need a method to bust a bubble, and when you call it you just use Instantiate to create a prefab and spawn it on the bubbles position and give it the correct velocity.
Something like (you must still add collision and stuff to call the method):
public class BubbleObject : MonoBehaviour {
public GameObject Bubble; // set in the inspector
public float speed; // set in inspector
public void Bust() {
for (int i=0; i < 3; i++) {
//Instantiate some bubbles (might have to play with the position)
Instantiate(Bubble, Bubble.transform.position, Quaternion.identity);
}
// Destroy our original bubble
Destroy(Bubble);
}
}