This is my first time making a 2d game. I'm trying to load a scene if the amount of objects with tag "Enemy" is zero. Line 22 doesn't seem to work. I don't get any errors.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelLoader : MonoBehaviour
{
public Animator transition;
public float transitionTime;
public GameObject enemyPrefab;
public GameObject[] enemy;
// Update is called once per frame
void Update()
{
if (enemy == null)
{
enemy = GameObject.FindGameObjectsWithTag("Enemy");
Debug.Log("null!");
LoadNextLevel();
}
}
public void LoadNextLevel()
{
StartCoroutine(LoadLevel(SceneManager.GetActiveScene().buildIndex + 1));
}
IEnumerator LoadLevel(int levelIndex)
{
transition.SetTrigger("Start");
yield return new WaitForSeconds(transitionTime);
SceneManager.LoadScene(levelIndex);
}
}
enemy = GameObject.FindGameObjectsWithTag("Enemy");