Hi everyone, i was just wondering how i get a particlular component from my hierarchy i am after a ParticleEmitter but i want the one named “ParticleEffect_walk” as i have different logic for different particles to be emitted.
I currently have (from tutorial)
var playerController : ThirdPersonController = GetComponent(ThirdPersonController);
// Init the particles to not emit
var particles : Component[] = GetComponentsInChildren(ParticleEmitter);
which gets all emitters but i really only want the one that has the name “ParticleEffect_walk”.
Thanks guys!
You could iterate through the array of components, or just create a public variable of type ParticleEmitter and assign through the inspector the particular emitter you want.
Thanks, but i made a mistake the particle emitter is not called PartilceEffect_walk i guess this is the prefab? sorry new to unity. It has the emitter, renderer etc inside it. I have a number of these and need them to only emit under certain conditions.
For eample if swimming emit the emitter under ParticleEffect_Bubbles if walking ParticleEffect_dirt etc.
This is sorta what i’m after but it ofcause doesn’t work.
var effect = GetComponent(ParticleEffect_FrontSlide);
emitter = effect.ParticleEmitter;
emitter.emit = false;
Thanks for your help, i’m thinking this is fairly straight forward as i would imagine this is a requirement for most games.
http://forum.unity3d.com/viewtopic.php?p=357428#357428
this was my thread on the subject it was solved at the end you just need to add your own methodology to “function OnControllerColliderHit(hit : ControllerColliderHit)”
instead use “function Update”
or “function Swimming”
or whatever you will use
and “if (swimming)” instead of
“if (hit.gameObject.tag == “Firepit”)”
basicly the method is there you just need to apply it to your own needs the working script is near the bottom and make sure that Autodestruct is unchecked in the Particle Animator believe me it will save endless headaches
hope this helps
and oh yeah as far as finding exact emiters my one was called “Fireball” in this script so look for that in the script and that is how you find the exact emiter you want
Works a treat, thank you very much!
glad to have helped
at least somebody benefits from my mistakes :twisted:
You can also use GameObject.Find() and look for it by name.