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

532
Visualizações
Get a list of Transforms in unity

I am trying to get a list of Transforms for a spawn system. I have tried to use GameObject.FindGameObjectsWithTag with an array instead of a list and it seems like the array needs to be GameObjects and not Transforms, since that's what it's looking for. I've also tried another piece of code, but it only returns one random Transform into a list, here it is:

public List<Transform> t;

void Start()
{
    t.Add(GameObject.FindWithTag("Spawn").transform);
}

As you can see in my code, it will only add one Transform to my list. I would like to add multiple Transforms instead of just one.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

You can use Linq Select like

using System.Linq;

...

public List<Transform> t;

void Start()
{
    t = GameObject.FindGameObjectsWithTag("Spawn").Select(go => go.transform).ToList();
} 

This basically somewhat equals doing

t = new List<Transform>();
foreach(var go in GameObject.FindObjectsWithTag("Spawn"))
{
    t.Add(go.transform);
}
over 4 years ago · Santiago Trujillo Relatório

0

Array of gameObject:

GameObject[] gos;
gos = GameObject.FindGameObjectsWithTag("Enemy");

To get the transform:

gos[0].transform

To make a list of transform:

public List<Transform> t;

foreach (GameObject go in gos)
{
   t.Add(go.transform);
}
over 4 years ago · Santiago Trujillo Relatório

0

It might be simpler to add these "spawn" objects to the list at the time of their creation instead of trying to find them afterwards. Is that an option?

For example:

GameObject spawn = Instantiate(spawnObj);
t.Add(spawn.transform);
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