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

531
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 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