Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FoodSpawner : MonoBehaviour
- {
- public List<GameObject> items;
- List<GameObject> tempItems = new List<GameObject>();
- GameObject item;
- Vector3[] initialSpawnPos;
- public List<Vector3> spawned = new List<Vector3>();
- List<int> SpawnIndex = new List<int> { 0, 1, 2 };
- List<int> tempSpawnIndex = new List<int>();
- void Start()
- {
- tempSpawnIndex = new List<int>(SpawnIndex);
- initialSpawnPos = new Vector3[3];
- initialSpawnPos[0] = new Vector3(256f, 41.48f, 242.21f);
- initialSpawnPos[1] = new Vector3(254.44f, 41.29f, 239.68f);
- initialSpawnPos[1] = new Vector3(256.81f, 41.19f, 239.79f);
- tempItems = new List<GameObject>(items);
- for (int i = 0; i < 3; i++)
- {
- GameObject generated = Instantiate(uniqalObject(tempItems.Count), initialSpawnPos[i], Quaternion.identity);
- spawned.Add(generated.transform.position);
- }
- }
- public void Spawner()
- {
- for (int i = 0; i < initialSpawnPos.Length; i++)
- {
- if (spawned.Contains(initialSpawnPos[i]))
- {
- tempSpawnIndex.Remove(i);
- }
- }
- GameObject generated = Instantiate(uniqalObject(tempItems.Count), initialSpawnPos[freeslot(tempSpawnIndex.Count)], Quaternion.identity);
- spawned.Add(generated.transform.position);
- }
- GameObject uniqalObject(int a)
- {
- if (a == 0)
- {
- tempItems = new List<GameObject>(items);
- }
- int index = Random.Range(0, a);
- item = tempItems[index];
- tempItems.Remove(item);
- return item;
- }
- int freeslot(int a)
- {
- int res = 0;
- if (a == 0)
- {
- tempSpawnIndex = new List<int>(SpawnIndex);
- }
- int index = Random.Range(0, a);
- res = tempSpawnIndex[index];
- tempSpawnIndex.Remove(res);
- return res;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement