x


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

more ▼

asked May 23 '12 at 09:12 AM

Danzou gravatar image

Danzou
220 16 27 40

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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

}

more ▼

answered May 23 '12 at 09:24 AM

venkspower gravatar image

venkspower
284 17 24 27

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.

May 23 '12 at 09:29 AM Danzou

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.

:)

May 23 '12 at 09:38 AM senad

I believe arrays in JavaScript are completely different, so I don't really know how to convert this =P

May 23 '12 at 10:00 AM Danzou

What do you want to convert this to?

May 23 '12 at 10:01 AM venkspower

Well I'd like to implement this in my main script, which is in JavaScript.

May 23 '12 at 05:50 PM Danzou
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2087
x1362
x885

asked: May 23 '12 at 09:12 AM

Seen: 399 times

Last Updated: May 23 '12 at 05:50 PM