Arrays. Access elements within elements

Hello and thanks for your attention!

How do I access specific elements withing array elements?

For example with an array of vextor3's; what I'd like to do is take array element1 and subtract it from array element2.

array element2[2,3,4] - array element1[1,2,3] = result of [1,1,1]

...somehow...? :?

--Goody!

In UnityScript you can subtract Vector3's just as normal:

var arr : Array = new Array();
arr.Add (Vector3.one);
arr.Add (Vector3.one*2);
arr.Add (Vector3.one*3);
arr.Add (new Vector2 (1,1));
Debug.Log ( (arr[0]-arr[3]) );

In C# it becomes a bit more complicated, you will need to convert the type from Object to Vector3, you do that like this:

ArrayList arr = new ArrayList ();
arr.Add (Vector3.one);
arr.Add (Vector3.one*2);
Debug.Log (( (Vector3)arr[0]-(Vector3)arr[1]));

Hope that helps ;)

it's easy let's assume that you have Vector3[] v;

then you can access elements like this

v[0]=v[1]-v[2]; v[n]; v[n].x;

you shoul replace n with a zero based element number. statements other than the first one are not real statements and are just examples. it is a syntax error to have v[n] as a statement. what i wrote was C# code and i don't know if it works on javascript or not

It sounds like you're confusing two issues - how to access an array element, which is explained by Ashkan. If you have an array "myarray" of integers, then myarray[0] is the first integer. If it's an array of Vector3, then myarray[0] contains a Vector3.

What you can do with those vectors is another matter. If you go to the Script Reference part of the Unity manual and look at the documentation for Vector3, you'll see a list of operations, including vector subtraction, addition, etc. The Script Reference also has a section about arrays.