List in unity code example
Example 1: how to create a public list unity
void Start ()
{
public List<BadGuy> badguys = new List<BadGuy>();
badguys.Add( new BadGuy("Harvey", 50));
badguys.Add( new BadGuy("Magneto", 100));
badguys.Add( new BadGuy("Pip", 5));
badguys.Sort();
foreach(BadGuy guy in badguys)
{
print (guy.name + " " + guy.power);
}
badguys.Clear();
}
Example 2: unity list
GameObject Obj;
List<GameObject> Objects = new List<GameObject>();
Objects.Add(Obj);
Example 3: how to create a list in c# unity
List<Datatype> listName = new List<Datatype>();
ex: List<float> myList = new List<float>();
Example 4: unity list
GameObject Obj;
List<GameObject> Objects = new List<GameObject>();
Objects.Add(Obj);
Objects.remove(Obj);,
Objects.Insert(0,Obj);
Objects.RemoveAt(0);