It’s a lot easier than it sounds. I need help trying to script my game to choose from 20 GameObjects that I have in an array, and to reduce it to just 6 randomly selected objects. Can someone please help me? Thanks in advance!
One way to tackle this is to declare a list then have it remove an element for as long as the list count is greater than 6:
public List<GameObject> myList;
void Start()
{
while(myList.Count > 6)
{
myList.RemoveAt(Random.Range(0, myList.Count));
}
}
1 Like