How to choose a random preference (complicated)

Before the game starts, the player has 5 preferences, a b c d and e, and he can enable and disable as many as he wants. For example

a - enabled
b - disabled
c- enabled
d - enabled
e - disabled

When the player enters a trigger, a random preference (a b c d or e) is chosen. If the preference is disabled, this preference won’t be put into the random choice. Since there are so many different combinations the user can have, is there a simple way to do this other than writing out every single possible combination that the user may have chosen? I know I will use ontriggerenter and Random.Range, but not sure where to go from there

Thanks

Hi,

On trigger enter, you want your app to compute 5 times a little routine to set randomly your preferences ? Are those references booleans ? Or ints/floats ?

If it’s a boolean choice, here’s a way to do this:

  • if (preference is disabled) → return;
  • else: throw a random value
  • and : if random value is > to .5f set preference to true, else set to false
  • apply new value to preference

Now you loop in all your preferences with a foreach :slight_smile:

If it’s not a boolean choice, but floats, use random.range and set the output value to your preference or make a switch case on a random.range with integers