using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FoodSpawner : MonoBehaviour {
public GameObject[] foodArr;
public int foodDelay = 10;
public Transform spawnArea;
private int foodCount;
private GameObject[] foodCountArr;
private GameObject food;
private Vector3 spawnLocation;
private Vector3 spawnPosition;
private Quaternion spawnRotation;
void Start()
{
spawnLocation = spawnArea.transform.position;
StartCoroutine (FoodSpawn());
}
void Update()
{
foodCountArr = GameObject.FindGameObjectsWithTag("Food");
foodCount = foodCountArr.Length;
}
IEnumerator FoodSpawn()
{while (true)
{
for (int i = 0; i < foodCount; i++)
{
food = foodArr[Random.Range(0, foodArr.Length)];
spawnPosition = new Vector3
((spawnArea.transform.position.x + Random.Range(-150, 150)),
24.925f,
(spawnArea.transform.position.z + Random.Range(-150, 150)));
spawnRotation = Quaternion.identity;
Instantiate(food, spawnPosition, spawnRotation);
yield return new WaitForSeconds(foodDelay);
}
}
}
}