- Home /
Position Array
I've asked this question before, but I still can't really figure it out. Arrays are one of my biggest weaknesses.
I've got an array with objects in it. I want another array to store their Z positions, so later on I can move them back to those positions. I can't figure out how to do this, if someone could make an example script, that would be awesome.
Thanks in advance, Daan
Answer by venkspower · May 23, 2012 at 09:24 AM
I hope you are trying this. Try this:
var a = new Array(A : GameObject,b : GameObject,c : GameObject);
var b = new Array(40,50,60);
function Update(){
a[0].transform.position.z = b[0];
a[1].transform.position.z = b[1];
a[2].transform.position.z = b[2];
}
But that means I'll manually take every single item in the array, which kinda beats the function of an array, right? If have threehundred objects in that array... I must copy that line threehundred times... That doesn't seem effecient.
Then you have to use a for-loop like this:
for ( int i = 0; i < a.length; ++i ) {
a[i].transform.position.z = b[i];
}
I do not know the name in Javascript, but there should be a field that tells you the length of your array.
:)
I believe arrays in JavaScript are completely different, so I don't really know how to convert this =P
Well I'd like to implement this in my main script, which is in JavaScript.
Your answer
![](https://koobas.hobune.stream/wayback/20220613071827im_/https://answers.unity.com/themes/thub/images/avi.jpg)