[Question] Unity slider range between max and min excluding values

Hello,
is there any way to exclude a number from the slider, i have the slider as the following:
Min Value = 7
Max Value = 13
I want exclude number 12 from the range.

Is that possible ?

Thanks in advance :smiley:

Rather than reading the value of the slider directly, you would read it through a function that performed that logic for you. It’s something you’d need to code. I guess something like this (in pseudocode):

public int GetFilteredSliderValue() {
  return (slider.value == 12) ? 0 : slider.value;
}

Of course that adds a new value (0) which you might not want - in which case set the range of the slider 7-12, and return 13 instead of 12 using the code above.

Of course this isn’t very flexible, so you might instead declare an array of ints and use the slider value (set at 0-5) to pick the appropriate element from the array, something like this:

  private int[] okvalues = new int[7,8,9,10,11,13];

  public int GetFilteredSliderValue() {
    return okvalues[slider.value];
  }

@ninjachimp how to achieve this in code?, i mean like where to put this method

Thanks :slight_smile:

Privacy & Terms