I’m trying to change the spawn area to fit the camera.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemySpawner : MonoBehaviour
{
[SerializeField]
private GameObject swarmerPrefab;
[SerializeField]
private GameObject bigSwarmerPrefab;
[SerializeField]
private GameObject flashPrefab;
[SerializeField]
private GameObject tankPrefab;
[SerializeField]
private float swarmerInterval = 3.5f;
[SerializeField]
private float bigSwarmerInterval = 10f;
[SerializeField]
private float flashInterval = 5f;
[SerializeField]
private float tankInterval = 10f;
// Start is called before the first frame update
void Start()
{
StartCoroutine(spawnEnemy(swarmerInterval, swarmerPrefab));
StartCoroutine(spawnEnemy(bigSwarmerInterval, bigSwarmerPrefab));
StartCoroutine(spawnEnemy(flashInterval, flashPrefab));
StartCoroutine(spawnEnemy(tankInterval, tankPrefab));
}
private IEnumerator spawnEnemy(float interval, GameObject enemy)
{
yield return new WaitForSeconds(interval);
GameObject newEnemy = Instantiate(enemy, new Vector3(Random.Range(-5f, 5), Random.Range(-6f, 6f), 0), Quaternion.identity);
StartCoroutine(spawnEnemy(interval, enemy));
}
}