I'm making a game that's similar to Binding of Isaac. There's a room with 4 doors and I want the doors to open after all the enemies are dead. I tried this code
using UnityEngine;
using System.Collections;
public class DoorOpen : MonoBehaviour {
GameObject[] enemies = (GameObject[])GameObject.FindGameObjectsWithTag("Enemy01");
void Update () {
if (enemies.Length == 0) {
Destroy (this.gameObject);
}
}
}
but I get an error that says "NullReferenceException: Object reference not set to an instance of an object". What did I do wrong?
↧