Adding upper and lower bounds to the slider
Unity allows us to add lower and upper bounds to sliders in a very simple way. Inside the Slider (Script) component, there are two variables named Min Value and Max Value. If we take the slider from the previous recipe and change the values of these variables, we'll see that we can drag the handle of the slider to the end and the value has an upper bound, as we can see in the following screenshot:
In this recipe, we will write a script to block the handle of the slider as well in order to make the player perceive a real upper or lower bound.
How to do it...
- So that we don't recreate another slider, we can take the one from the previous recipe; thus, we can also see the value as a percentage. Otherwise, simply right-click on the Hierarchy panel and then click on UI | Slider.
- For the next step, we need to create our script on the slider. So, click on Add Component | New Script, name it UpperAndLowerBoundsForSlidersScript, and then click on...