How to place particle systems into an array and randomly play one at a time?


Is it possible to store multiple particle systems into an array and randomly play one at a time? I am trying to get a particle system to play for every enemy that is defeated but would like to randomize it to give it a little more variety. Here is the code I have at the moment.

    Rigidbody2D rigidbody2;
        public float deathTimer;
        private GameController gameController;
        //public GameObject[] attackParticleSystems;
        public ParticleSystem[] attackParticleSystems;
        public ParticleSystem ps;
        void Awake()
            gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameController>();
            rigidbody2 = GetComponent<Rigidbody2D>(); 
            ps = GetComponent<ParticleSystem>();
        //Lifespan of Projectile
        private void Start()
            ps = attackParticleSystems[Random.Range(0, attackParticleSystems.Length)];   

I tried placing brackets after public ParticleSystem reference, but the inspector would not allow me to place any particle system prefabs in it. The next thing I tried was to go about the GameObject route, which did allow me to place the objects there but gave me an error (Cannot implicitly convert type ‘UnityEngine.GameObject’ to ‘UnityEngine.ParticleSystem’ [Assembly-CSharp]csharp(CS0029)).

So, unfortunately, I am stuck at the moment. If anyone could help or perhaps point me in the right direction, I would really appreciate it!

You cant have multiple particle systems on on a single GameObject.

Create an object with some child gameobjects that have ParticleSystems on them and then using a script on their parent you could get their particle systems like:

    ParticleSystem[] ParticleSystems;

    void Start()
        ParticleSystems = GetComponentsInChildren<ParticleSystem>();

The organisation of your game objects is really superfluous the premise it the same though.