- Home /
How to create a Particle effect after a time limit
Hello! I'm currently testing a few levels for my project, and I needed to create an explosion after a short time limit. (For exemple: An explosion after 5 seconds)
I have my explosion particle set in place, but I just need a script to activate my explosion after a time limit.
If you guys have any kind of script that works or else a another answer that sounds familliar to this one, please post them below! :D
Thanks!
~LittleL0L
Answer by $$anonymous$$ · Mar 09, 2013 at 01:13 AM
Try this:
//js
function Start()
{
particleEmitter.enabled = false; // turn the particle system off at startup
yield WaitForSeconds (5); // wait for 5 seconds
particleEmitter.enabled = false; // turn the particle system on
}
I always get this error:
$$anonymous$$issingComponentException: There is no 'ParticleEmitter' attached to the "explosion" game object, but a script is trying to access it.
That's because you didn't attach the script to the gameobject that actually has a particle system, or you are using shrukin and not legacy, in witch case it should be
function Start() {
yield WaitForSeconds (5); // wait for 5 seconds
ParticleSystem.Play(); // turn the particle system on
}
Sorry the code isn't formatted: I'm doing this on my tablet
Still dosen't work:
Assets/Timer.js(3,19): BCE0020: An instance of type 'UnityEngine.ParticleSystem' is required to access non static member 'Play'.
Hey guys just saw this thread, and although I highly doubt crusherxman is still in any need of help after all these years, someone might else might be having a similar issue. Ben-Jarrell 's code is very useful and is what I used, and if you are using a relatively new version of Unity (Which uses Shuriken) see Ben's comment (2nd above $$anonymous$$e). This will probably give you an error (See the comment just above $$anonymous$$e) if you haven't declared a variable for ParticleSystem. Just add this above his function Start line :
private var ParticleSystem : ParticleSystem;
Works on $$anonymous$$e, and I hope I helped someone :)
Answer by RyanZimmerman87 · Mar 09, 2013 at 02:32 AM
yield WaitForSeconds(); is probably the superior method for performance.
Another easy way to do it is just create an int variable timer. Set it to 0 on Start. Then do something like this:
int timer = 0;
Update()
{
if (timer > your desired number)
{
//put your particle effect/explosion stuff here
timer = 0;
your condition = false;
}
}
In FixedUpdate()
{
if (your condition)
{
++timer;
}
}
But this will increment timer every physics step if the "your condition" variable is true, witch will base the timer off of the physics fps, not off of the actual time
Edit: in your code that you wrote, you forgot to declare methods with void and "your condition" is not a possible variable name nor was it declared as a boolean
Answer by SectionScreen · Mar 09, 2013 at 12:53 PM
var lifeTime = 1.0;
function Awake ()
{ Destroy (gameObject, lifeTime);
}
Your answer
Follow this Question
Related Questions
How to instantiate a particle and make it play? 1 Answer
Making detonator explosions follow the gameobject 2 Answers
scripting Impact explosion 1 Answer
Explosive like in COD 4? 1 Answer
Help on a Power-Up Sequence 1 Answer