hi need to load all the prefabs in the resources folder into an array. the script is below. the problem is when i run the script it shows an error message as below. i dont know where am making mistake. need help on how to load the prefabs.
NullReferenceException: Object reference not set to an instance of an object
runtime.Start () (at Assets/scripts/runtime.cs:22)
using UnityEngine;
using System.Collections;
public class runtime : MonoBehaviour {
public int rows;
public int columns;
public int n = 3;
int initialPositionX = -5;
int initialPositionY = 5;
float bufferSpace = 1.5f;
public Transform prefab;
public GameObject[] items;
// Use this for initialization
void Start () {
items = new GameObject[];
items = Resources.LoadAll("prefabs")as GameObject[];
//Debug.Log(items.Length);
int index = Random.Range(0, items.Length);
cardCreation(index);
}
// Update is called once per frame
void Update () {
}
public void cardCreation(int cardIndex)
{
float spaceBetweenCards = prefab.transform.localScale.x;
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
Instantiate(items[cardIndex], new Vector3((j*bufferSpace+spaceBetweenCards),(i*bufferSpace+spaceBetweenCards),0),
Quaternion.Euler(270,0,0));
}
}
}
}