Random Player Selection

Options
I am trying to select a random player to be a killer but I haven't been successful. I could use some help on how to successfully make a random player a killer.

Comments

  • I've been searching for a method for this too but just coming across dead ends, did you find a solution?
  • S_Oliver
    S_Oliver ✭✭✭
    edited October 2020
    Options
    Hy, you actually need 2 things.

    1.
    Selecting a random index from a list or array is something that you should already know.
    But I'll give you an Example.
    List<string> ListOfStrings = new List<string>() { "This", "is", "a", "list", "of", "strings" };
    string randomStringFromList = ListOfStrings[Random.Range(0,ListOfStrings.Count)]; 
    

    2. You need to "tag" a player, means a way that this informations is available for everyone.
    A simple way would be to use the Room properties. With room properties you can store any key-value and this informations is available for everyone in the Room, you could store the player name. Read through the doc's to get more information.

    There are also some Tutorials about Room properties that should guide you in the correct direction.

    For an more "advanced" example you can look here this is a wrapper to simplify the usage and here and Example.