- Home /
Array - insert item in the middle
I'm using UnityScript. I want to insert an item in the middle of an array (in the specific position).
var arr: Array = new Array(String);
arr.Push("A");
arr.Push("B");
arr.Push("D");
arr.Push("E");
arr.Insert(2, "C");
I've used "splice" method in ActionScript for that. How can I do it in Unity?
Answer by Eric5h5 · Apr 03, 2012 at 02:22 AM
Never use Array, use List instead. Specifically, List.Insert. (Note that Unityscript's syntax for generics uses an extra "." compared to C#, such as List.<String>
rather than List<String>
. Also "import" instead of "using", such as import System.Collections.Generic
. But otherwise it works the same.)
Thanks a lot! I've been searching for ActionScript Vector. analogy.
I'm surprised that all these things are poorly documented by unity $$anonymous$$m.
They're poorly documented by the Unity $$anonymous$$m because they're not Unity-specific. Look up the $$anonymous$$SDN reference for all your .net needs. There's no need for the Unity $$anonymous$$m to document this stuff, because $$anonymous$$icrosoft has already done it!
Your answer
Follow this Question
Related Questions
Access a variable of a class stored in an array. 2 Answers
TextAsset inside the Array - UnityScript/JavaScript 1 Answer
How to delete new'd arrays? 2 Answers
JS Array Object to Float 1 Answer
How do i check if all tagged objects are inactive? 2 Answers