- Home /
How to get an object to follow the Slider knob?
Hi there, long time dev, first time poster. I'm trying to access the knob piece of a UI Slider and make a sprite just above it follow along. I have this code, which won't work probably because the y-value is being set to the ACTUAL value of the slider's progress (which I believe should be in the range of 0.0 to 1.0, so I am unable to see it):
//public GameObject Target;
//public float m_Speed;
public Slider SliderDis;
//private float y;
// Use this for initialization
void Start () {
//m_Speed = 10.0f;
}
// Update is called once per frame
void Update () {
this.transform.position += new Vector3(0.0f, SliderDis.value, 0.0f);
}
Also, it seems that when you pull down the Slider hierarchy you aren't able to access the knob as a separate object. So how do I make my little sprite man follow along the progress path?
Is there a reason you don't just use the little guy as your slider knob itself?
Yes, it's the way a certain in-game meter is supposed to work and look
You can access the knob's RectTransform
with sliders, it's the .handleRect
property.
It can be a little tedious to orient things based on screenspace used by the UI elements, but you can get the desired result pretty easily by creating a second, non-interactive slider that uses your little guy as its knob and follows your actual slider's value.
Your answer
Follow this Question
Related Questions
Lagging/unmoving slider 0 Answers
Slider moving on hover 0 Answers
Use Slider for Geometry (GameObject) 'layers' 1 Answer
Slider moving on hover 0 Answers
Balance UI Sliders 1 Answer