- Home /
Problem is not reproducible or outdated
how see if the array has been filled
so i made array but i don't know if my array is filled, i just want to know if all of my array is filled, i want to make debug.log("slots is full"), how can i do that ??
Answer by SpeakBeaver · Aug 09, 2018 at 02:39 PM
Use a variable to check if he is filled, you start with the hypothese that he is fill and if you have a null element so your hypothese is wrong and he is not fill.
bool fill = true;
for(int i=0; i< slotG.length ; i++){
if(slotG[i] == null){
fill = false;
break;
}
}
if(fill){
Debug.Log("Is filled");
}
I do this technic for all my projects and it works ^^ An other solution is to fill the array at the start with a default GameObject and check if the actual object in the loop is equal to this one to know if it's not fill
a third solution is to have an external variable who is incremented every time you add an object. and check if this variable is equal to your array's length