- Home /
Is it possible to change the element name in an Array List?
Hi,
I am creating an array List of Vector3 values like this:
var attackerWayPointArray = new List.<Vector3>();
Rather than having each value named as 'Element 0', 'Element 1' etc, I would like to be able to change the element name to something more like 'Start' so that I can search for the Vector3 value by name.
This is so that I can refer to the way-points as they will be constantly changing.
Is this possible?
Answer by fafase · Dec 08, 2012 at 04:04 PM
What you describe is a dictionary:
http://msdn.microsoft.com/en-us/library/xfhwa508.aspx
var myDic = new Dictionary.<String, Vetcor3>();
myDic["Start"] = Vector3(10,10,10);
transform.position = myDic["Start"];
You could also use http://msdn.microsoft.com/en-us/library/system.collections.hashtable.aspx
facepalm Thanks fafase.I had heard of dictionary and hashtable before, but never realised that they could be used this way. Is there much of a performance difference between dictionary and hashtable?
Brilliant! $$anonymous$$y list of Unity Bookmarks is growing fast ;)
Your answer
Follow this Question
Related Questions
String as variable name, reflection or dictionary or other 2 Answers
Array of named booleans 2 Answers
How to check if a vector 3 is in a vector 3 array c#. 1 Answer
How to I play an animation using the Animation Element Array via Script? 0 Answers
How can I assign an Array of Vector3 while seeing and editing the values in the Scene? 0 Answers