1

I am making a game that's similar to Bindig Of Isaac and I have the same door system. I want the doors to open when the number of enemies in the scene == 0. I created this code but I always get an error that says NullReferenceException: Object reference not set to an instance of an object I have no idea why this is not working. Any advice?

using UnityEngine;
using System.Collections;

public class DoorOpen : MonoBehaviour {

GameObject[] enemies = (GameObject[])GameObject.FindGameObjectsWithTag("Enemy01");

    void Update () {

        if (enemies.Length == 0) {
            Destroy (this.gameObject);
        }


    }
}
TredOut
  • 57
  • 1
  • 8

0 Answers0