Answers for "unity dictionary"

C#
12

unity list

GameObject Obj;
List<GameObject> Objects = new List<GameObject>();

Objects.Add(Obj);
Posted by: Guest on April-05-2020
3

unity dictionary

//create dictionary "test", with key as float and value as GameObject
private Dictionary<float, GameObject> test = new Dictionary<float, GameObject>();

//add thing to dictionary
private void addToDictionary()
{
  //add key 10 and this gameObject
  test.Add(10, transform.gameObject);
}

private void printFromDictionary()
{
  //try to get value and save it as out GameObject result
  test.TryGetValue(10, out GameObject result);
  //then print that result
  print(result);
}

private void deleteFromDictionary()
{
  //remove key and gameObject 10 from our Dictionary
  test.Remove(10);
}
Posted by: Guest on April-22-2021
7

how to create a list in c# unity

List<Datatype> listName = new List<Datatype>();
ex: List<float> myList = new List<float>();
Posted by: Guest on March-26-2020
0

unity foreach dictionary

foreach(var key in someDictionary.Keys) // loop through keys
foreach(var value in someDictionary.Values) // loop through values
foreach(KeyValuePair<K, V> p in someDictionary) // loop through both
Posted by: Guest on April-16-2020
1

dictionary in c# unity

public class ScriptA : MonoBehaviour{
    public Dictionary<string, GameObject> dictio = new Dictionary<string, GameObject>();
}
Posted by: Guest on October-25-2020
1

Dictionaries in unity

Dictionary<keyClass,valueClass> dictionaryName;
dictionaryName = new Dictionary<keyClass,valueClass>();
Posted by: Guest on October-20-2020

C# Answers by Framework

Browse Popular Code Answers by Language