- Home /
How can i get the index of an array[] as int?
hello!
i got an array of Vector3[] and i would like to get specific Vector3s of this array by knowing their array number as int. how can i get this number?
for example, a gameobject has 3 positions (3 different Vector3 positionVec). when elsewhere an int position is set to 1, i want to target the positionVec[1], and if position is set to 2, i want to target positionVec[2] and so on!
thanks in advance for your help.
no i am looking for positionVec[howCanIGetTheArraynumberOfAnObjectInsideThisArrayAsInt]
oh well, when i read your line again.. actually i think this is what i want, yes! how do i get it?
You will have to search for through some mechanism.
Iterate through the array using a for() loop
Use System.Array.IndexOf()
Put it in a generic List and use List.IndexOf()
Use LINQ
http://answers.unity3d.com/questions/432047/how-do-you-use-indexof-or-findindex.html
http://msdn.microsoft.com/en-us/library/e4w08k17(v=vs.110).aspx
There is also a LINQ tutorial on www.unitygems.com.
Depending on where you get the values for comparison, you may want to compare the distance between the Vector3s rather than a direct comparison.
Your answer
Follow this Question
Related Questions
Moving an Object to the vector of other objects on button press using a vector3 array? 0 Answers
Array.Push() for Vector3[] or how to add items to Vector3 array without knowing index 1 Answer
NGUI - Vector 3 Position different from position 1 Answer
store instantiated in Array. c# 1 Answer
Position in Vector (C#) 1 Answer