I’ve been trying to find some, but theyre all usually in C# and overly complex.
Im trying to create a dynamic variable, such as combining a string and integer to create a reference to a pre-existing variable. (Where you simply change out the integer to reference the next variable, so the string would be constant, but the integer could be changed and switched out during run-time)
Many have asked this question, but all the answers have been either “Not sure what youre talking about” or “Go learn arrays, you noob”
So, any recomendations where i can start? thank you.
(Unity’s documentation doesnt help a noob like me)
I don’t know any good unity specific tutes (did you check the wiki?) but can provide a working sample to get you running.
#pragma strict
import System.Collections.Generic;
function Start() {
// declare / initialise
var dict: Dictionary.<String, int> = new Dictionary.<String, int>();
// populate data
dict["Shanghai"] = 17836133;
dict["Istanbul"] = 13710512;
dict["Tehran"] = 13244535;
dict["Mumbai"] = 12478447;
// retrieve data
for(var city: String in dict.Keys) {
Debug.Log("City: " + city + ", Pop: " + dict[city]);
}
}
This is using a .NET Dictionary, MSDN have thorough coverage of its methods and usage. You will also find the .NET community is huge if you search “.NET Dictionary tutorial” you will get plenty of hits.
The only real gotcha to watch out for is the unusual period “.” in the unityscript syntax for declaration and initialisation.