Accessing one among several children's particle system

Hi!

My player game object has several dummy children, each one containing a ParticleSystem.
I use them to trigger several effects whenever needed (since attaching several particle systems to one gameobject is impossible I think).

I’m trying to figure out the correct way to do this (c#):

GetComponentInChildren("particle_stars").GetComponent<ParticleSystem>().enabled=true;

I can’t use transform.Find since I have two players that both have the same children, as you can see on the picture.

30461-untitled-1.jpg

I might also be approaching this the wrong way…any suggestions?

Thank you!!

You could run a method like so:

private ParticleSystem GetSystem (string systemName){
    Component[] children = GetComponentsInChildren<ParticleSystem>();
    foreach (ParticleSystem childParticleSystem in children){
        if (childParticleSystem.Name == systemName){
            return childParticleSystem;
        }
    }
    return null;
}

This is just written off the fly, there is probably a better way to do it. There are probably also mistakes, but the principle should work.