- Home /
Weird UI slider behaviour
Hello everyone,
So I've built this UI system where I can delete multiple items from the inventory using a slider. However, I've encountered some weird behaviour. I have some simple code where if the player press the right of left arrow the value of the slider will increment of decrement. This works as intended until I drag the slider bar or click on another part of the bar to change the value after I do that then the value will increment or decrement by two instead of one when using the arrow keys and this will continue until I click somewhere else on the screen.
Here's the simple increment/decrement code:
if (Input.GetKeyDown(KeyCode.LeftArrow)) {
if (deleteSlider.value <= deleteSlider.maxValue || deleteSlider.value >= deleteSlider.minValue) {
deleteSlider.value -= 1;
}
}
if (Input.GetKeyDown(KeyCode.RightArrow)) {
if (deleteSlider.value < deleteSlider.maxValue || deleteSlider.value > deleteSlider.minValue) {
deleteSlider.value += 1;
}
}
I have no idea why this is happening. Hopefully someone has an answer.
Thanks.
Answer by Arcana96 · Nov 28, 2017 at 03:02 AM
Well, for anyone who comes across this and is as silly as me! The Slider has it's own behaviour for incrementing and decrementing the slider value and when I clicked on it I activated that behaviour!. If you'd rather only have your own behaviour then you can disable the sliders navigation by going to the Slider Component and setting "Navigation" to "None".
Your answer
Follow this Question
Related Questions
Oculus VR Drag Slider With Finger 0 Answers
Unity 2D - Text UI and Textbox scripting issue - HELP ASAP! 2 Answers
ui problem 0 Answers
Dynamic slider size with the new UI 2 Answers
left end of slider fill flattening the more i move the value down 0 Answers