Check through array list
How would I check through an array list of booleans, and check if every single array element is set to true?
Comment
Answer by ml4c · Aug 04, 2016 at 11:46 AM
If you are using an array:
bool[] arrayList;
bool everyTrue=true;
for (int i=0;i<arrayList.Length;i++){
if(arrayList[i]==false){//only if one element or more are false the bool gets changed
everyTrue=false;
}
}
if(everyTrue){
print("every Item is true");
}
If you are using a List (there is probably a better way to do it but I think it works):
List<bool> list=new List<bool>();
bool[] arrayList = list.ToArray();
bool everyTrue=true;
for (int i=0;i<arrayList.Length;i++){
if(arrayList[i]==false){//only if one element or more are false the bool gets changed
everyTrue=false;
}
}
if(everyTrue){
print("every Item is true");
}
Your answer
Follow this Question
Related Questions
I'm trying to make the collision work. But... 2 Answers
Automatic Switching of two or more booleans in Inspector 1 Answer
Why does my Gem counter not work? (screenshot included for explanation / easy code) 1 Answer
Calling Bool in Network Command Not Working 0 Answers
Reading a var from variable parents 1 Answer