Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

115
Vistas
Check active state of gameObject in List

I have 4 gameObjects in a List. I would like to check the count of active gameObjects from this list. As in if two gameObjects are active, that means count is 2. How would be the best way to get the count?

public List<GameObject> Total_GO;

public void Start()
{
  //Get Count of active gameObjects
}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can simply use Linq Count and as a filter use GameObject.activeInHierarchy or GameObject.activeSelf according to your needs

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);
}

or if you rather want to actually use the active objects 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)
    {
        ...
    }
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda