I’m trying to make a .io game, and I’m trying to make it so that when “players” spawn and choose a random username, the username element they just chose gets removed from the list to prevent other “players” from using the same username. Here’s a image of the code (It’s for testing, but still):
First thing is, you are declaring ‘names’ as an Array, not a List, and you are right assuming it should be a List
Also, you don’t need the for loop because you already know the index of the string you want to delete.
A possible solution could be:
// Define it as a List, not an Array
public List<string> names = new List<string>();
private string m_selectedName;
void RandomName()
{
if (Input.GetKeyDown(KeyCode.N))
{
// Choose a random index
int num = Mathf.RoundToInt(Random.Range(0, names.Count-1));
// Save the selected name
m_selectedName = names[num];
// Remove from list
names.RemoveAt(num);
}
}
Just modify the name of the method and the way you store the selected name to your needs.
Hope this helps @ExplodingCreeperMakesGames