Hello in my resources folder I store various “bandit” prefabs and I create a script that’s supposed to generate a random “bandit” prefab out of it.
Problem is that I dont know how to loop through that resources folder any help would be very helpful
Make sure to have your bandits named correctly in your resource folder and have the last part of name be an integer than utilize this code to your liking.
using UnityEngine;
using System.Collections;
public class resourcesLoop : MonoBehaviour {
public int randomBandit;
public GameObject banditClone;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyUp(KeyCode.Space))
{
randomBandit = Random.Range(1,6); //Random bandit 1-5 (6 is excluded)
banditClone = Resources.Load("bandit"+randomBandit) as GameObject;
Debug.Log(banditClone);
banditClone = Instantiate(banditClone, transform.position, transform.rotation) as GameObject;
}
}
}