using System.Collections.Generic; using UnityEngine; public class SpawnItems : MonoBehaviour { public List<GameObject> itemsList = new List<GameObject>(); private List<GameObject> itemSpawnPoints = new List<GameObject>(); private void Awake() { foreach (GameObject spawn in GameObject.FindGameObjectsWithTag("ItemSpawn")) { itemSpawnPoints.Add(spawn); } int randGear = Random.Range(0, 10); int i = 0; while (i < randGear) { int randPos = Random.Range(0, itemSpawnPoints.Count); if (!itemSpawnPoints[randPos].GetComponentInChildren<Item>()) { int randItem = Random.Range(0, itemsList.Count); Instantiate(itemsList[randItem], itemSpawnPoints[randPos].transform); i++; } } Debug.Log("Item Spawning Complete"); } }