- Home /
Question by
Magixxar · Nov 12, 2020 at 03:32 PM ·
staticlistsupdate function
Trouble Using a Static List
I use something like this in my code:
public static List objects = new List(); // Contains a set of objects
public List objects2 = new List(); // Empty
public List objects3 = new List(); // Empty
System.Random rand = new System.Random();
void Start()
{
objects2 = objects;
}
void Update()
{
GameObject temp = objects2[rand.Next(0, objects2.Count)];
objects2.Remove(temp);
objects3.Add(temp);
}
but on each update the members of the objects2 list is reset, as if nothing has been removed from it. But when I use something like this:
void Start()
{
foreach (GameObject obj in objects)
{
objects2.Add(obj);
}
}
void Update()
{
GameObject temp = objects2[rand.Next(0, objects2.Count)];
objects2.Remove(temp);
objects3.Add(temp);
}
It acts properly as it should.
I don't know why this happens. Can someone provide some craifications?
Comment