- Home /
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);
}
}
Answer by DaveA · Mar 27, 2012 at 07:26 PM
I've seen this type of thing, I think it's a bug. Try splitting it:
var emitter : ParticleEmitter;
emitter = GetComponentInChildren(ParticleEmitter);
Answer by by0log1c · Mar 27, 2012 at 07:47 PM
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
I partially solved my problem, I'm not sure what the problem was, but it wasn't code issues.
Your answer
Follow this Question
Related Questions
How to make particle emitters attached to specific parts of a player model? 1 Answer
FPS Projectiles launching backwards 1 Answer
Lens flare as missile, make it dissapear? 1 Answer
FPS Tutorial 3 : Robot rockets spawning below mesh 1 Answer
Is there any performance or memory usage diffrence? 0 Answers