- Home /
when all array are null,all objects in array are null
hi all, I wanna know if all the array are null...
var greenFood: GameObject[];
function Awake()
{
if(GameObject.FindWithTag("GreenFood")){
greenFood= GameObject.FindGameObjectsWithTag("GreenFood");
}
}
when my char pass through the objects I destroy it, and in array one of then stay null, I want to know when all the array are null
thanks
Comment
Best Answer
Answer by Tiryth · Feb 01, 2012 at 09:13 PM
hi all... I figure out how to solve this XD
var count : int;
var greenFood: GameObject[];
function Awake()
{
if(GameObject.FindWithTag("GreenFood")){
greenFood= GameObject.FindGameObjectsWithTag("GreenFood");
}
}
function Update(){
count= 0;
for(var i = 0; i < greenFood.Length; i++){
if (greenFood[i] == null)
{
count++;
}
}
if(count == greenFood.Length){
print("green");
}
}
$$anonymous$$ark your own answer as the correct one (also in http://answers.unity3d.com/questions/212171/how-to-find-if-all-objects-in-array-are-missing.html)! So the issue will be closed.