unity list
GameObject Obj;
List<GameObject> Objects = new List<GameObject>();
Objects.Add(Obj);
unity list
GameObject Obj;
List<GameObject> Objects = new List<GameObject>();
Objects.Add(Obj);
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);
}
how to create a list in c# unity
List<Datatype> listName = new List<Datatype>();
ex: List<float> myList = new List<float>();
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
dictionary in c# unity
public class ScriptA : MonoBehaviour{
public Dictionary<string, GameObject> dictio = new Dictionary<string, GameObject>();
}
Dictionaries in unity
Dictionary<keyClass,valueClass> dictionaryName;
dictionaryName = new Dictionary<keyClass,valueClass>();
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us