Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

114
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda