I'm using a list to find and store a gameobjects child transforms in. I use a list mainly because I don't want all childs of the go, only the ones taged "Detachable" and for some go's that use the script they are quite a few so would be a pain adding them in the inspector.
Anyways, I now want to add the code to pick a random index from the list and add it to a new object kinda like:
Transform _detach = _myArray[Random.Range(1, _myArray.Length);
Is it possible to do something similar to this with a List?
asked Mar 02 '11 at 02:40 PM
Yes, you'd want something like:
i.e. Lists have "Count" instead of "Length".
Also note that the lower bound on the Random Range is 0, not 1 (which should be the case in yours too).
And finally, note that the upper bound on Random Range is exclusive for the integer version (different than the float version) so the maximum it would return is Count - 1.
answered Mar 02 '11 at 02:50 PM
Also, you should probably change your variable name from
answered Mar 02 '11 at 02:51 PM