- Home /
Question by
berting01 · Feb 23, 2012 at 07:41 PM ·
timeparticlesystemparticleeffect
how to trigger a firework
I have already made a simple firework. what I want to do is trigger it. I want to know how will be able to put a time on the firework that i made. for example, every 5 seconds,the firework will explode.. how to to that in java scrip. Am I going to use the renderer.enabled? thanks heres my code:
var firework : GameObject;
var trigger : ParticleEmitter;
function Start(){
trigger = firework.GetComponent(ParticleEmitter);
}
function Update(){
if(Input.GetKeyDown(KeyCode.Mouse1)){
trigger.enabled = true;
}
}
Comment
Best Answer
Answer by adrenak · Feb 24, 2012 at 04:02 AM
You have to use InvokeRepeating, it is used to repeatedly call a function. So you can use it to repeatedly trigger the particle system. Find info here : link
do something like this :
//have the same start function
var firework : GameObject;
var trigger : ParticleEmitter;
var n : int;
InvokeRepeating ( "fireworks", 3,2); //you can change the values instead of 3 and 2 to 5 seconds as you said
function fireworks(){
trigger.enaled = true;
//we also have to stop emmiting the particles after 'n' seconds
yield WaitForSeconds(n); //change the value of n to what you want
trigger.enabled = false;
}
I Hope this helped !