x


Particle Emitter exists, but my script can't find it

This function is supposed to find the emitter that the object has, but it never gets into the if. (It's the code from the fps tutorial) I don't get why it doesn't exist.

function Kill ()
{
// Stop emitting particles in any children
    var emitter : ParticleEmitter = GetComponentInChildren(ParticleEmitter);
    if (emitter)
    {
       emitter.emit = false;
       transform.DetachChildren();
       Destroy(gameObject);
    }
}
more ▼

asked Mar 27 '12 at 07:24 PM

iguana72 gravatar image

iguana72
2 3 5 6

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

2 answers: sort voted first

I've seen this type of thing, I think it's a bug. Try splitting it:

var emitter : ParticleEmitter;
emitter = GetComponentInChildren(ParticleEmitter);
more ▼

answered Mar 27 '12 at 07:26 PM

DaveA gravatar image

DaveA
26.8k 153 171 257

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

I've had similar issues before, now I don't trust the GetComponentsInChildren anymore. IIRC, I've got the generic version to work more often than the normal method. I wouldn't swear it but you give it a try tell us, heh.

GetComponentInChildren.<ParticleEmitter>(); //JS syntax requires a dot
GetComponentInChildren<ParticleEmitter>(); //C# doesn't
more ▼

answered Mar 27 '12 at 07:47 PM

by0log1c gravatar image

by0log1c
2.1k 6 9 18

I partially solved my problem, I'm not sure what the problem was, but it wasn't code issues.

Mar 28 '12 at 03:48 AM iguana72
(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:

x326
x261
x91
x38

asked: Mar 27 '12 at 07:24 PM

Seen: 770 times

Last Updated: Mar 28 '12 at 03:48 AM