I’m very new to Unity. Every other case of this problem I’ve seen has occurred because they have forgotten to instantiate a new list, but I think I’ve done that okay… I keep getting the aforementioned error at the line indicated with comment. Any ideas why? My goal is to spawn blocks and have them be automatically destroyed once they fall a certain distance. Thanks in advance.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class SpawnBox : MonoBehaviour {
public Rigidbody SpawnedBox;
static List<GameObject> SpawnedBoxList;
void Start ()
{
SpawnedBoxList = new List<GameObject>();
}
void Update ()
{
if (Input.GetButtonDown("Jump"))
{
GameObject instanceBox = Instantiate(SpawnedBox, transform.position, transform.rotation) as GameObject;
SpawnedBoxList.Add((GameObject)instanceBox.gameObject); //NULL REFERENCE EXCEPTION HERE
}
//for (int i = 0; i < SpawnedBoxList.Count; ++i)
//{
// if (SpawnedBoxList*.gameObject.transform.position.y < -100)*
// {
// Destroy(SpawnedBoxList*.gameObject);*
// }
//}
* }*
}