I am having trouble with for each loop,
here is the loop
public class map : MonoBehaviour
{// Use this for initialization
void Start () {
Leaf[] leafs = new Leaf[10];
foreach (Leaf l in leafs)
{
l.leftChild = new Leaf();
l.rightChild = new Leaf();
}
}
and hear are the sub leaf defenitions. but for some reason the game tells me
NullReferenceException: Object reference not set to an instance of an object
map.Start () at l.leftChild = new Leaf();
public class Leaf
{
public Leaf leftChild; // the Leaf's left child Leaf
public Leaf rightChild; // the Leaf's right child Leaf
}
and I am just not sure why its giving me the error. any thoughts are appreciated.