How do I detect when a user clicks on my slider rather than just sliding?

I am using a Slider control to get feedback from a user in Unity. I know how to detect when the user changes the value of the slider.

However, I can’t seem to figure out a way to detect if the user just clicks on the current position of the slider if he doesn’t want to move it. I would like to avoid adding other visual controls.

Is there any way to detect when the user clicks on the slider?

1 Answer

1

If you’ve ever worked with interfaces, there are a number of interfaces that may be of use to you, like the IMoveHandler, ISelectHandler, and ISubmitHandler interfaces.

Specifically, the question you’re asking is what to do when the user’s mouse clicks on the GameObject.

This interface will probably be of good use to you:

https://docs.unity3d.com/ScriptReference/EventSystems.ISelectHandler.html

Write a script that interfaces with this and implement the proper functions to handle what you want to happen when the user selects the object. Than attach this script to the slider.

More on interfaces:

EDIT: I’m attaching something similar I did for a previous project, just cleaning up some code and it’ll be there in a moment