Hey. So, I have script that instantiates objects from an array randomly, but the Resources.LoadAll function is not finding the game objects for some reason. Debug.Log prints null. The folder name is correct (checked a bunch of times) and it is located at the root of resources. Here’s the code:
using UnityEngine;
using System.Collections;
public class PersonSpawner : MonoBehaviour {
public GameObject[] personArray;
public Boundary boundary;
void Awake () {
personArray = Resources.LoadAll("Persons") as GameObject[];
}
void Start () {
InvokeRepeating ("SpawnPerson", 0.0f, 1.5f);
Debug.Log(personArray);
}
void SpawnPerson () {
Vector3 randomPosition = new Vector3
(
Random.Range (boundary.xMin, boundary.xMax),
Random.Range (boundary.yMin, boundary.yMax),
-1.25f
);
if(CubeMover.keepClosed == false)
{
GameObject person = Instantiate
(
personArray[Random.Range(0,personArray.Length)],
randomPosition,
Quaternion.identity
)
as GameObject;
}