- Home /
Disable slider dragging at specified value
Hey guys
I need to stop a slider's handle from sliding beyond a specified point along its track.
I don't need the slider to be disabled or inactive, I just need the handle to basically "hit an invisible wall" beyond which it cannot slide any further.
Anyone know of a way to do this using C#?
CONTEXT:
I have a character setup scene where the player has X number of points they can distribute between several character stats (health, stamina, mana, etc.) in any ratio they like.
I've done this using sliders for each stat, but the sliders need to stop sliding if there are no more points available to allocate to those stats).
Thanks in advance!
Answer by FlyingHighUp · Oct 14, 2017 at 03:31 AM
If you are using the Unity UI system, you can assign the slider value to force it back. E.g.
slider.normalizedValue = 0.7f;
So in a method the slider calls OnValueChanged(), assign position of the slider if the player doesn't have enough points.
Answer by Dozy- · May 18, 2019 at 06:25 AM
Hi all, I'm doing something similar. Can someone explain @FlyingHighUp answer to @DarkRebirth ? I know the using UnityEngine.UI; and that normalizedValue gives the slider value between 0 and 1. I'm not sure about the mainSlider.onValueChanged.AddListener(delegate {ValueChangeCheck(); });. Does that go in an if statement in the public void Update? Does the ValueChangedCheck have the if statement? I'm trying different combination, but can't figure it out. Any help is appreciated!
Your answer

Follow this Question
Related Questions
Slider to modify a countdown time in another scene 0 Answers
Reverse slider min/max values 0 Answers
Keep Draggable UI window within Canvas? 1 Answer
how to create GUI slide effect ?? 1 Answer