Hello everyone!. I have this little script that, with declarations and stuff ignored, SHOULD, change the color of a prefab, instance it, add it to an ArrayList and then print the colors of every object in the array list.
My problem is that, when I instance them and add them to the list, all is good, but when I search its colors, the instanced objects all gave NullReferenceExeption.
I was hoping someone could look at it and spot something im missing here.
Thanks in advance!
void Start () {
timer = 0;
ballList = new ArrayList();
}
void Update () {
timer += Time.deltaTime;
if (ballList.Count < 10)
{
if (timer > 0.5)
{
RandomizeColors(ballPrefab); //randomizes and assigns a material.
clone = Instantiate(ballPrefab, transform.position, transform.rotation) as GameObject;
lista.Add(clone);
timer = 0;
}
}
else
{
foreach (GameObject ballz in lista)
{
Debug.Log(ballz.renderer.material.name); //NULL REFERENCE EXEPTION
//here goes the code that searches for balls of the same color and deletes
them
}
}
}