I’m doing Challenge 3, the Bombs and Ballon, but my SpawnManager isn’t working! I fixed the error and checked everything, but nothing is happening. What am I doing wrong?!
public GameObject[] objectPrefabs;
private float spawnDelay = 2;
private float spawnInterval = 1.5f;
private PlayerControllerX playerControllerScript;
// Start is called before the first frame update
void Start()
{
InvokeRepeating("SpawnObjects", spawnDelay, spawnInterval);
playerControllerScript = GameObject.Find("Player").GetComponent<PlayerControllerX>();
}
// Spawn obstacles
void SpawnObjects ()
{
// Set random spawn location and random object index
Vector3 spawnLocation = new Vector3(30, Random.Range(5, 15), 0);
int index = Random.Range(0, objectPrefabs.Length);
// If game is still active, spawn new object
if (!playerControllerScript.gameOver == false)
{
Instantiate(objectPrefabs[index], spawnLocation, objectPrefabs[index].transform.rotation);
}