Search Unity

How to get vector values out of an array?

Discussion in 'Scripting' started by techmage, Mar 7, 2010.

  1. techmage

    techmage

    Joined:
    Oct 31, 2009
    Posts:
    2,133
    So I am trying to do

    myArray.Push(Vector3(10,2,6));

    and then I am trying to get the value out of that by going

    myArray[0].x

    but that doesn't work.

    How do I get the x value off the Vector3 that I pushed into the array?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Actually that does work if you use dynamic typing, so I guess you must be using #pragma strict. It needs to be cast to a Vector3:

    Code (csharp):
    1. var arrayElement : Vector3 = myArray[0];
    --Eric
     
  3. techmage

    techmage

    Joined:
    Oct 31, 2009
    Posts:
    2,133
    thank you