Hello,
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!