I’ve been working on a simple construction for my system. Below I have the script that’s supposed to delete any game objects with a specific tag however it never seems to return null even when no game objects with that tag exist.
Documentation on FindGameObjectsWithTag
function Instantiate_Ghost(building_type:GameObject)
{
var OtherGhosts : GameObject[] = GameObject.FindGameObjectsWithTag("Building_ghost");
if (OtherGhosts != null) //check to see if there are other construction ghosts
{
print("OtherGhosts != null");
for (var ghost in OtherGhosts)//Cycle through each other ghost and delete it.
{
print("We're destroying a ghost");
Destroy(ghost); //delete the ghost
OtherGhosts = null;
}
}
else //OtherGhosts == null
{
print("We're making a ghost object");
Instantiate (building_type, Vector3(0, 0, 0), Quaternion.identity);
}
}