I’m following the unity documentation and I found exactly what I was looking for. The sample script in the documentation is
// Search for game objects with a tag that is not used
function Start () {
var gos : GameObject[];
gos = GameObject.FindGameObjectsWithTag("fred");
if (gos.length == 0) {
Debug.Log("No game objects are tagged with fred");
}
}
I did pretty much the same thing.
using UnityEngine;
using System.Collections;
public class DoorOpen : MonoBehaviour {
void Start () {
var enemies : GameObject[];
enemies = GameObject.FindGameObjectsWithTag("Enemy01");
}
void Update () {
if (enemies == null || enemies.Length == 0) {
Destroy (this.gameObject);
Debug.Log ("Enemies array has no enemies in it.");
}
if (enemies.Length > 0) {
Debug.Log ("Enemies array has enemies in it.");
}
}
}
However, this doesn’t work. I get this error. Assets/DoorOpen.cs(7,29): error CS1525: Unexpected symbol
:‘, expecting )',
,’, ;',
[', or ='