- Home /
Timed explosion?
I have this script attached to an object. It destroys it a second or so after it's created, and I want it to create a particle emitter once it does. However, the way I have it now, it just constantly instantiates the particle emitter on the object until it's destroyed. I'm also not really sure how the timer works in the first place.
Here's the code:
var explosion : ParticleEmitter; var timer : float = 1.0;
function Update () {
Destroy(gameObject, timer);
Instantiate(explosion, transform.position, transform.rotation);
}
Answer by DaveA · Apr 18, 2011 at 04:21 AM
var explosion : ParticleEmitter; var timer : float = 1.0; var createTime : float = 0.0;
function Start() { createTime = Time.time; } function Update () { if ((Time.time - createTime) > timer) { Destroy(gameObject, timer); Instantiate(explosion, transform.position, transform.rotation); } }
that is a really smart way :) but can i ask what is Time.time ?
For some reason it didn't work. It's still constantly creating the particle emitter like usual.
Well, now there's pause before it constantly explodes. It should only explode once.
In the particle system that you instantiate do you have the "looping" box checked? You may need to put the explosion inside an empty object and attach a script very much like this one to it if that doesn't solve the problem.
Your answer
Follow this Question
Related Questions
CountDown Timer for Explosion 0 Answers
timed bomb, explosion detection 2 Answers
Dual Timer Problems 1 Answer
Explosive like in COD 4? 1 Answer
Can't get 2d bomb to explode on timer 2 Answers