Hi,
I have 2 particle emitters on a game object. It has 2 modes to emit it.
Getting hit = blood, Getting hit while blocking = dust.
var hitParticles : ParticleEmitter;
var blockParticles : ParticleEmitter;
function Start ()
{
hitParticles = GetComponentInChildren(ParticleEmitter);
blockParticles = GetComponentInChildren(ParticleEmitter);
}
Now I call hitParticles.Emit(); or blockParticles.Emit(); with the corresponding collision.
But it always calles second one, the Dust emitter (blockParticles).
Any ideas why?
I put the right Sparks emitter in the right ParticleEmitter slot. But it seems like it can only have one Particle Emitter.
It looks like you are getting the same component since you are calling the exact GetComponentInChildren for both hitParticles and blockParticles. You can try finding the particle emitter as a name and getting the component using Transform.Find.
More info here: Unity - Scripting API: Transform.Find
Ahaa, okay, I’ve never used find.
The following doesn’t work:
hitParticles = ParticleEmitter.Find(“sparkBlood”);
blockParticles = ParticleEmitter.Find(“sparkDust”);
hitParticles = GetComponentInChildren(“sparkBlood”);
hitParticles = transform.Find("sparkBlood").GetComponent(ParticleEmitter);
blockParticles = transform.Find("sparkDust").GetComponent(ParticleEmitter);
It’s Transform.Find. The function is part of Transform, not ParticleEmitter.
Thanks, It works!
I always have a hard time understanding the .transform and game object elements.
Most of the time I use the wrong one and can’t convert them into what I need.
closestObject = GameObject.FindWithTag(“Player”);
Doesn’t work if you want to get it’s position but:
closestObject = GameObject.FindWithTag(“Player”).transform;
Does work. Learning all the time 