hello all, I would create a gameObject spawner, but I have a great problem, I can’t check the number of entity in the range (the number become very large)
public class Spawner : MonoBehaviour
{
public GameObject mob;
public float radius = 10;
public int maxEntity = 5;
string mobName;
int number;
float dist;
int timer = 120;
List<GameObject> mobSpawnList = new List<GameObject> ();
void Start ()
{
mobName = mob.name;
}
void OnDestroy()
{
mobSpawnList.Remove (mob);
print ("destroyed");
}
void Update ()
{
timer--;
if (timer < 1) {
Spawn ();
timer = 120;
}
GetNumber ();
dist = Vector3.Distance (mob.transform.position, transform.position);
print (number);
OnDestroy ();
}
void Spawn ()
{
if (number <= maxEntity) {
Instantiate (mob, transform.position, Quaternion.identity);
}
}
public int GetNumber()
{
if (dist <= radius) {
mobSpawnList.Add (mob);
number = mobSpawnList.Count;
}
return number;
}
}