how to create a dictionary in unity code example
Example 1: dictionary in c# unity
public class ScriptA : MonoBehaviour{
public Dictionary<string, GameObject> dictio = new Dictionary<string, GameObject>();
}
Example 2: unity dictionary
private Dictionary<float, GameObject> test = new Dictionary<float, GameObject>();
private void addToDictionary()
{
test.Add(10, transform.gameObject);
}
private void printFromDictionary()
{
test.TryGetValue(10, out GameObject result);
print(result);
}
private void deleteFromDictionary()
{
test.Remove(10);
}