Hey everyone!
Here is a quick code chunk, I’m trying to add particles to a list when they’ve been selected (this is just an example script tho, all the extra bits are removed). Usually I just tell something to add itself to a list if it’s not contained within the list, this allows it to only be added to the list once…blah blah blah…
But in this case…it seems to continuously add it anyway…so where have I gone wrong? In any case, if you can see what I’m trying to do and know of a better solution that would be appreciated as well!
Thanks in advance!
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class asdfasdf : MonoBehaviour {
ParticleSystem.Particle[] myPart;
List<ParticleSystem.Particle> myPartList = new List<ParticleSystem.Particle>();
List<string> myTestString = new List<string>();
void Start () {
myPart = new ParticleSystem.Particle[GetComponent<ParticleSystem>().maxParticles];
}
void Update () {
//TODO : This works...
/*
if (!myTestString.Contains ("HI"))
myTestString.Add ("HI");
print (myTestString.Count);
*/
//TODO : This Doesn't...
GetComponent<ParticleSystem> ().GetParticles (myPart);
for (int i = 0; i < GetComponent<ParticleSystem>().maxParticles; i++) {
if(!myPartList.Contains(myPart[i])){
myPartList.Add(myPart[i]);
myPart[i].color = Color.red;
}
else{
myPart[i].color = Color.green;
}
}
GetComponent<ParticleSystem>().SetParticles(myPart, GetComponent<ParticleSystem>().maxParticles);
print (myPartList.Count);
}
}