How do I make a random player generator?

Hi, Could someone please tell me how to make a random player generator button? So I’m making a game that currently can be played with 5 players, but I’m thinking of adding a “?” random button which selects any player from that 5 player list. I’ve searched everywhere and cannot find a good answer. If anyone could help that would be great!! Thanks

To select a random object from a list of objects,

  1. create the list:

    public List players;

  2. fill it inside the editor.

  3. Select one, using the Random Class.

    GameObject randomPlayer = players[Random.Range(0, players.Count)];