The code digs through child nodes to pull out materials so I can animate the shield materials. The material is found as the error occurs inside an if statement requiring a material named shield. I’m confused as to why the line shields.Add(m); throws a null reference exception. Also I cant get code tags to work?
code:
public class ShipCtrl : MonoBehaviour {
private List<Material> shields;//stores all shields for submeshes
void Start () {
//find all shields and store in shields list
Material[] materials;
foreach (Transform childMesh in transform)
{
materials = childMesh.renderer.materials;
foreach (Material m in materials)
{
print(m.name);
if (m.name == "shield (Instance)")
{
shields.Add(m);
print("found Shield");
}
}
}
}
Guess the code tags did work...
– mccaber