Hi guys,
I was wondering if I could convert a single array to use as a Vector3 position?
So for example I have a number of arrays in a list and I want just one position:
myArray[1] // Has the position (0,0,9)
I would like this position to be used as a Vector3 so I can Instantiate a prefab.
Can this be done?
Neil.
Why not just use an array of vectors? As in:
var myArray[] = new Vector3[arraySize];
myArray[0] = new Vector3(1, 2, 3);
And so on.
jister
January 15, 2013, 1:20pm
3
if i understand correct you have 3 floats sitting at myArray’s index [1]?
myPos=Vector3(myArray[1]);
dunno if that would work.
easiest would be to store them in an array of vector3’s i guess the you could
Instantiate(prefab, myArray[1], transform.rotation);
or run a for loop assigning the array’s content to x,y,z
what type are the arrays?
edit:hehe i was to s l o w …
Thankx for the replies.
What I’m saying is the array has been made with the positions for each cell (the script is for a maze).
They are stored in this Transform array:
public List<Transform> CompletedSet = new List<Transform>();
If this helps.
P.S. = Forgot to mention the array was a Transform, sorry
Neil
Then get the position from the Transform using the, wait for it, position property.
Vector3 v = CompletedSet[0].position;
I think you might benefit from spending some time learning (or even relearning) the basics of C# and programming. Someone suggested the Yellow Book earlier today on some other thread. Might be worth checking out.
Thank you shaderop, I’ll look at this yellow Book page. Mind you though I was close I did try “transform.position” but looks like I was nowhere near.