Hello!
I have made an empty GameObject which is my randomSpawner and added this script on it:
using UnityEngine;
using System.Collections;
public class RandomSpawner : MonoBehaviour
{
bool isSpawning = false;
public float minTime = 5.0f;
public float maxTime = 15.0f;
public GameObject[] enemies; // Array of enemy prefabs.
float randomY = Random.Range(-5f,0.0f, 5f);
float rightScreenBound = 10;
IEnumerator SpawnObject(int index, float seconds)
{
Debug.Log ("Waiting for " + seconds + " seconds");
yield return new WaitForSeconds(seconds);
// Instantiate(enemies[index], transform.position, transform.rotation);
// Vector3 position = new Vector3(Random.Range(-10.0F, 10.0F), 0, Random.Range(-10.0F, 10.0F));
Instantiate(enemies[index], new Vector3(rightScreenBound, randomY, 0), Quaternion.identity);
//We've spawned, so now we could start another spawn
isSpawning = false;
}
void Update ()
{
//We only want to spawn one at a time, so make sure we're not already making that call
if(! isSpawning)
{
isSpawning = true; //Yep, we're going to spawn
int enemyIndex = Random.Range(0, enemies.Length);
StartCoroutine(SpawnObject(enemyIndex, Random.Range(minTime, maxTime)));
}
}
}
Actually it is only spawning an Object “behind the Scenes” and it’s always on the same Position.
I want to spawn objects in a circle around my spawnObject (randomSpawner),
Do you know what is Happening wrong?
Thank you