Random role assignment (Documentation only!)

This is a continuation of a previous post where I wrote: “I have a system in place where I have a list of roles, cops /robbers, which is assigned in the inspector in the form of a string. How can I write a script which randomly assigns all agent a role, either cops or robbers , every time I start a new game?”


Since then I was given a script but, after having tinkered with it for a while, I realized that wasn’t what I needed. There already exists scripts which allow you to randomly change material of an object based off a list I was wondering if it was possible to the same for an array of strings in this case called roles?


I need documentation ONLY no scripts please.

Well, if you have an array of strings, you could generate a random index using int randIndex = Random.Range(0, array.Length - 1) and then retrieve the string using array[randIndex]. If you did this inside of the Start function, you could use this to accomplish what you’re wanting?