Spawning Particle Effects From Code Does Nothing

I made a Squirtle and I want to make it do a Bubblebeam attack that starts and continues for a few seconds, then gets destroyed, then has a wait before it can be done again. I want the Bubblebeam to spawn from his tongue, which is a separate part of the mesh. And the Bubblebeam is a particle effect. My code goes like this:

Heading

static function UseBubblebeam (Tongue : GameObject, 
                               BubblebeamPrefab : GameObject, 
                               Bubblebeam : Transform) {
if (Input.GetKey("[1]")){
    var BubblebeamAttack : GameObject = Instantiate (BubblebeamPrefab, Tongue.transform.position, Tongue.transform.rotation);
    yield WaitForSeconds(3.0);
    Destroy (Bubblebeam);
    yield WaitForSeconds(5.0);
    }
}

There are no error messages but when I press the button nothing happens… Does this have to do with the input? (and I have tried both the numPad and the row at the top of the keyboard)

You’re checking for Input.GetKey inside the function UseBubblebeam. You should check for input in Update, since it’s called each frame.

EDITED AGAIN: Answer edited to destroy the instantiated object after 3 seconds, and to include a reload time of 5 seconds:

var Tongue : GameObject;
var BubblebeamPrefab : GameObject;
var nextShot : float = 0;

function UseBubblebeam () {

	var BubblebeamAttack : GameObject = Instantiate (BubblebeamPrefab, Tongue.transform.position, Tongue.transform.rotation);
	Destroy (BubblebeamAttack, 3); // destroy automatically after 3 seconds
}

function Update(){

	if (Time.time>nextShot && Input.GetKeyDown("[1]")){
	
	    UseBubblebeam();
        nextShot = Time.time + 5; // next shot in 5 seconds   
	}
}

You must drag the objects you want to the variables Tongue and BubblebeamPrefab. When you press 1 in the keypad, BubblebeamPrefab will be instantiated at Tongue position, and will be destroyed automatically after 3 seconds. The reload time was set to 5 seconds.

The BubblebeamPrefab is an empty mesh with a particle system attatched. I’m starting to think it would’ve been smarter to just make the particle system on the tongue and make the emitter a boo. I’ll try experimenting with that but thanks a bundle for the help :smiley: