Tengo 4 gameObjects en una lista. Me gustaría verificar el recuento de gameObjects activos de esta lista. Como si dos gameObjects estuvieran activos, eso significa que el conteo es 2. ¿Cuál sería la mejor manera de obtener el conteo?
public List<GameObject> Total_GO; public void Start() { //Get Count of active gameObjects }Simplemente puede usar Linq Count y como filtro use GameObject.activeInHierarchy o GameObject.activeSelf según sus necesidades
using System.Linq; ... void Start() { // or obj.activeSelf according to your needs var activeCount = Total_GO.Count(obj => obj.activeInHierarchy); Debug.Log($"Active objects: {activeCount}", this); } o si prefiere usar los objetos activos, use Linq Where
void Start() { // or obj.activeSelf according to your needs var activeObjects = Total_GO.Where(obj => obj.activeInHierarchy).ToList(); var activeCount = activeObjects.Count; Debug.Log($"Active objects: {activeCount}", this); foreach(var obj in activeObjects) { ... } }