Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Getting an array of gameobjects with a certain tag

$
0
0
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?

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>