Search Unity

Slider with different thresholds

Discussion in 'Scripting' started by Gorki12, May 3, 2022.

  1. Gorki12

    Gorki12

    Joined:
    Jul 12, 2015
    Posts:
    73
    Hello,
    I want to create a battle pass system with different rewards depending on our player level.
    The thresholds with rewards for level gained are not proportional.
    For example, the first reward is for level 5, the second for level 8, the third for level 15. I have set the maximum value of the slider to 50 but for the value 8 there is no arrow from above the second arrow, but when value is 12. And my question is how to make the slider be above the second arrow when level 8, or above the third arrow when level 15, or somewhere in the middle of the second and third arrow when level 11?
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    Just use some kind of lookup table.

    Code (csharp):
    1. int[] Levels = new int[] {
    2. 1,
    3. 5,
    4. 8,
    5. 15,
    6. 50,
    7. 100,
    8. // etc
    9. };
    You can code it up as a list of intervals mapping the linear Slider input to your reward amounts.

    Alternately you can code it as preset ScriptableObjects that you slot into an array in the inspector.