I’ve been at this for a while now and can’t seem to find a solution to my problem. I am trying to get the enemy to randomly spawn outside of the camera field of view. The problem I am having is that when ever I play the game, the enemy’s always spawn in the corner of the screen. (I’m just using blocks because of testing)
Here is my scripts:
public GameObject[] enemy;
public int amount;
private Vector3 spawnPoint;
private float camMin;
private float camMax;
void Start()
{
camMin = Camera.main.orthographicSize;
camMax = Camera.main.orthographicSize + 2;
}
void Update ()
{
enemy = GameObject.FindGameObjectsWithTag ("Enemy");
amount = enemy.Length;
if (amount != 10)
{
InvokeRepeating ("spawnEnemy", 1f, 2f);
}
}
void spawnEnemy()
{
spawnPoint.x = Random.Range (camMin,camMax);
spawnPoint.y = Random.Range (camMin,camMax);
spawnPoint.z = 0;
Instantiate (enemy [UnityEngine.Random.Range (0, enemy.Length - 1)],spawnPoint, Quaternion.identity);
CancelInvoke ();
}
Thanks for the help!