Null reference exceptions occur when I try to reference an array gameObject from my levelGen script, not sure how to fix it as everything is set correctly in inspector
I've tried referencing gameObject's int in the array, directly calling it and messing around with different iterations of my instantiate script but can't seem to get it working.
LevelGen script
public GameObject[] blockPrefabs;
public GameObject[] blocks;
public int blockInt;
public GameObject blockInstance;
// Use this for initialization
void Start () {
//blocks = new GameObject[blockPrefabs.Length];
//for (int b = 0; b < blockPrefabs.Length; b++) {
//for (int y = 0; y < 5; y++) {
//for (int i = 0; i < 5; i++) {
//Duplicates square in each colour
//blocks [b] = (blockPrefabs
[b].gameObject); Random.Range (0,blockPrefabs.Length);
//blocks [b] = Instantiate(blocks [b],
new Vector3 (i * 5.0f, y * 5.0f, 0), transform.rotation);
for (int y = 0; y < 5; y++) {
for (int i = 0; i < 5; i++) {
blockInt = Random.Range (0,
blockPrefabs.Length);
Instantiate (blockPrefabs [blockInt], new
Vector3 (i * 5.0f, y * 5.0f, 0), transform.rotation);
Debug.Log (blockPrefabs);
Raycasting script
if (Input.GetButtonDown ("Fire1")) {
Ray raycast = Camera.main.ScreenPointToRay
(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast (raycast, out hit)) {
if ((hit.collider != null) &&
(hit.collider.gameObject == levelgen.blockPrefabs[0])) {
redselect.redchange = true;
Debug.Log ("red clicked");
combinations ();
} else {
Debug.Log ("failed red");
}
Be able to click on the instantiated object to run the rest of my code. At the moment when I click on it it returns null references.