In Unity, Is there a way I can set up either associative arrays
value{key} = float
or
just as well, can I explicity define multi-dimensional arrays like
value[xInt][yInt] = float
In Unity, Is there a way I can set up either associative arrays
value{key} = float
or
just as well, can I explicity define multi-dimensional arrays like
value[xInt][yInt] = float
If you’re using Javascript, then you can’t use multi-dimensional arrays. C# does support them though.
For an associative array, use Mono’s hashtable: Hashtable Class (System.Collections) | Microsoft Learn
If you were using C#, you could use a Dictionary also.
var foo = new Hashtable(); // Or "var foo = {};" if you want to be really terse
foo["something"] = "blah";
You can use multi-dimensional arrays in Javascript.
var foo = new Array(10);
foo[0] = new Array(10);
foo[0][0] = "blah";
You can even use multidimensional built-in arrays in Javascript:
var tdata = Terrain.activeTerrain.terrainData.GetHeights(0, 0, 32, 32);
tdata[10, 25] = .75;
You just can’t define them from scratch, apparently, for some reason.
–Eric
Thanks a lot for your advice.
I’ll give it a go.