unity dictionary code example
Example 1: unity list
GameObject Obj;
List<GameObject> Objects = new List<GameObject>();
Objects.Add(Obj);
Example 2: how to create a list in c# unity
List<Datatype> listName = new List<Datatype>();
ex: List<float> myList = new List<float>();
Example 3: dictionary in c# unity
public class ScriptA : MonoBehaviour{
public Dictionary<string, GameObject> dictio = new Dictionary<string, GameObject>();
}
Example 4: unity foreach dictionary
foreach(var key in someDictionary.Keys)
foreach(var value in someDictionary.Values)
foreach(KeyValuePair<K, V> p in someDictionary)
Example 5: adding to a dictionary unity
Dictionary<string , int> someDictionary
someDictionary.Add("Five" , 5);
Example 6: 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);
}