Here is my code can someone please help me to have these objects not spawn on top of each other?
using UnityEngine;
using System.Collections;
public class codecoin : MonoBehaviour
{
public Transform[] spawnPoints;
public GameObject[] enemyPrefabs;
public int amountEnemies = 20; // Total number of enemies to spawn.
public int yieldTimeMin = 0;
public int yieldTimeMax = 5; // Don't exceed this amount of time between spawning enemies randomly.
public int i;
void Update() {
yieldTimeMin = PlayMakerGlobals.Instance.Variables.GetFsmInt("coinmin").Value;
yieldTimeMax = PlayMakerGlobals.Instance.Variables.GetFsmInt("coinmax").Value;
amountEnemies = PlayMakerGlobals.Instance.Variables.GetFsmInt("coinamount").Value;
}
public IEnumerator Spawnblock()
{
for (i=0; i<amountEnemies; i++)
{
yield return new WaitForSeconds(Random.Range(yieldTimeMin, yieldTimeMax)); // How long to wait before another enemy is instantiated.
var obj = enemyPrefabs[Random.Range(0, enemyPrefabs.Length)]; // Randomize the different enemies to instantiate.
var pos = spawnPoints[Random.Range(0, spawnPoints.Length)]; // Randomize the spawnPoints to instantiate enemy at next.
Instantiate(obj, pos.position, pos.rotation);
}
}
}