x


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);

}
more ▼

asked Apr 18 '11 at 03:47 AM

Irsan gravatar image

Irsan
65 39 42 50

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
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);
  }
}
more ▼

answered Apr 18 '11 at 04:21 AM

DaveA gravatar image

DaveA
26.5k 151 171 256

that is a really smart way :) but can i ask what is Time.time ?

Apr 18 '11 at 05:55 AM MC HALO

For some reason it didn't work. It's still constantly creating the particle emitter like usual.

Apr 18 '11 at 06:49 AM Irsan

Oh sorry, I forgot an important line of code, fixed now

Apr 18 '11 at 03:28 PM DaveA

Well, now there's pause before it constantly explodes. It should only explode once.

Apr 19 '11 at 12:42 AM Irsan
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x347
x161
x15

asked: Apr 18 '11 at 03:47 AM

Seen: 956 times

Last Updated: Apr 18 '11 at 03:47 AM