how do I get a list of vectors from a list of gameobject []?

0

I'm having a question, for me I'm learning it's difficult, maybe for others it's easy.

I am using a list of objects installed in unity3d (gameobjects [])! basically what I want to do is that when instantiating a new object, it is added to the list of arrays, and automatically a list of vector3 is created to define its position ...

the list of objects does not have a limit, it can only be 4 objects or maybe 350 .. it varies according to how many objects you specify manually.

so if you instantiate 4 objects, something similar will appear in the list of objects.

obj0 = x (1,235), and (0.015), z (-0.789) obj1 = x (2,785), and (0,237), z (-2,943) obj2 = x (1,382), and (0.824), z (-5,158) obj3 = x (4.125), and (0.697), z (-6.437)

that the value takes it out automatically when instantiating the object, and that that position remains the same when instantiating a new object.

Then I want to select that object and mobilize it automatically, and that its value is updated as the value changes ...

It's hard for me because I'm getting into these equations, but maybe with some help I can do it!

thanks

    
asked by Gonzalo Rivero 03.10.2018 в 17:10
source

1 answer

0

You can pass the list by means of a foreach Example.

Foreach (Vector3 pos in gameobjects)
{
  pos = gameobtjects.transform.position; //igualas la variable Vector3 creada en el foreach a su Transform.position que es un Vector3
  myListVector.Add(pos); //Agregas el valor de la variable a la lista de Vector3
}

This can be helpful. You can check the Unity3D documentation Tranform.position and in Microsoft's documentation C # Foreach

You could also use just one list and with that manage what you need. (But everything depends on the case)

    
answered by 14.10.2018 в 08:14