So a long time ago I ran across some syntax that looked like which was sorta a double array. Now, I haven’t seen it used before and upon entering it into unity (ex. var texMap : Texture2D
I got a parser error about syntax and semicolons. So the main point of this is to ask if there is a way to make a double array.
2 Answers
2You cannot declare an explicit jagged array in Unity Script, you can in C#. You can implicitly create one, but that’s probably not really going to help you much. Your best bet is probably to create it using Lists.
You can declare such a list like this:
import System.Collections.Generic;
var myData = new List.< List.<GameObject> >();
This can be accessed using the syntax myData[0][1]; and is fully jagged.
Given that it’s a list you can also add and remove things from it.
myData.Add(new List.<GameObject>());
myData[0].Add(someGameObject);
Unityscript doesn’t directly support the syntax for jagged arrays. You can use 2D arrays, or a List of arrays (i.e., var textureArrayList = new List.< Texture2D[] >();), which amounts to pretty much the same thing as a jagged array.
http://answers.unity3d.com/questions/11963/how-to-create-multidimensional-arrays-in-javascrip.html http://answers.unity3d.com/questions/166326/2d-arrays.html http://answers.unity3d.com/questions/54695/how-to-declare-and-initialize-multidimensional-arr.html http://answers.unity3d.com/questions/337421/how-to-write-a-2d-array.html
– ByteSheep