Hello, I’m having some trouble with what I hoped to be a reasonably easy piece of code. My intention is for it set a GameObject variable to be a file ending in .prefab from a resources folder and then changing the name to be a number before adding it to a list and increasing said number until there’s no remaining GameObjects in the folder.
For some reason, it doesn’t want to work properly - but I’m getting no errors, so I have no clue what’s gone wrong.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class PrefabSetup : MonoBehaviour {
public static List<GameObject> prefabRooms = new List<GameObject>();
public static int prefabCount = 0;
void Start () {
int objectNumber = 0;
string objectNumberAsString;
bool prefabsLoaded = false;
while (prefabsLoaded == false) {
GameObject currentObject = Resources.Load("*.prefab") as GameObject;
System.Threading.Thread.Sleep (50);
if (currentObject == null) {
Debug.Log ("currentObject = null");
prefabsLoaded = true;
} else {
Debug.Log (currentObject.ToString ());
objectNumberAsString = objectNumber.ToString ();
currentObject.name = objectNumberAsString;
Debug.Log ("Set To: " + currentObject.ToString ());
prefabRooms.Add (currentObject);
objectNumber++;
prefabCount++;
}
}
}
void Update () {
}
}
Any help would be appreciated. The reason I’m doing it this way and not simply doing a GameObject array with a Resources.LoadAll is I eventually want to have a progress bar or loading percentage and I want it to visibly go through every file and load it one after the other.