Answer the question
In order to leave comments, you need to log in
Checking the state of elements in an array C# Unity. How?
There is an array of game objects, each has a boolean variable. Each element can have it on or off. The yes-no value of the entire array depends on the state of this variable. That is, if at least one element has bool=false, then the entire array answers "no". "Yes" only works when each element has bool=true.
Tell me how to check for this on / off for all elements inside the array?
Answer the question
In order to leave comments, you need to log in
Something like this.
using System.Linq;
bool otvet_massiva = massiv.All(element => element.buleva_peremenna);
Convert an array to a List with the ToList operation
Through linq, look for the number of elements with false or true.
If the number of elements with false > 0, then the result is false.
If the number of elements with true = the number of elements in the array, then the result is true.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question