Heya! So I’m trying to remove a material from a list by referring to a GameObject’s material. The list includes the material the GameObject has, as the material for the GameObject is infact given from the list. However, when I refer to the GameObject’s material in an attempt to remove it from the list, this does not work. Here’s the code:
void Start () {
materials.Add (blue);
materials.Add (yellow);
materials.Add (green);
midRend = middleCube.GetComponent<MeshRenderer>();
midRend.material = materials[Random.Range(0, materials.Count)];
}
void OnTriggerEnter2D(Collider2D col) {
int ranIndex;
Material save;
if(col.tag == "MiddleCube") {
save = midRend.material;
materials.Remove(save);
ranIndex = Random.Range(0, materials.Count);
midRend.material = materials[ranIndex];
//materials.Add(save);
}
}
What could be of help here? It seems as if the material I’m plugging into the middle cube is actually an instance and not the actual material, so I think this might be the problem. How could I make it not an instance? Thanks.