I’m trying to create a prefab, that I can place anywhere on a map (2D top down shooter) using insideUnitCircle to randomise the spawns somewhat but keeping them inside a general area and not outside of map boundaries.
Here is my script so far:
public class SpawnCircle : MonoBehaviour {
public GameObject enemyType;
public int enemyCount;
public float spawnDelay;
public float spawnRate;
public float spawnRadius;
private int counter;
// Use this for initialization
void Start (){
counter = 0;
}
void OnTriggerEnter2D(Collider2D other) {
if (other.gameObject.tag == "Player") {
Destroy (GetComponent<Collider2D> ());
InvokeRepeating ("Spawn", spawnDelay, spawnRate);
}
}
void Spawn() {
Instantiate(enemyType, transform.position = Random.insideUnitCircle * spawnRadius, transform.rotation);
counter = counter + 1;
if (counter == enemyCount)
Destroy (this.gameObject);
}
}
Unfortunately this will place the centre of the spawn area at map co-ordinates 0,0.
How can i move the centre of the circle to where i have placed my prefab?
Any help would be much appreciated.