Skip to main content
Source Link
Gnemlock
  • 5.3k
  • 5
  • 30
  • 60

The original asker edited their question with the solution they used. However, as questions should not be edited to include the answers, I have removed the code to post as a community wiki.


The original asker reports that they used this code to meet their requirements:

function Update (){
    for (var i =0; i < OppoCount.length ; i ++){
        if(OppoCount.length > 0) {
            if (OppoCount[i].gameObject == null){
                OppoCount.RemoveAt(i);
            }

        if(OppoCount.length < HowMany){
            StartCoroutine ("Spawn");
        }
    }
}

function Spawn(){
    var length = Oppos.length - 1;
    var index = Mathf.Round(length*UnityEngine.Random.value);
    curSpawn = Oppos[index];

    var xz = Random.insideUnitCircle * spawnSizeArea;
    var newPosition = Vector3(xz.x,0,xz.x) + transform.position;

    yield WaitForSeconds(Random.Range(2,4));

    var newOp : GameObject = Instantiate(curSpawn, newPosition, transform.rotation);

    OppoCount.Push(newOp);
    StopCoroutine("Spawn");
}
Post Made Community Wiki by Gnemlock