- Home /
Question by
OrbitGames · Sep 11, 2014 at 05:36 PM ·
uislider4.6
ugui 4.6 Slider automatic reset
I want the Slider value to be zero once you release the handle.
How can you achieve this?
Comment
Best Answer
Answer by orb · Sep 11, 2014 at 06:17 PM
This does the trick:
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class Val : MonoBehaviour, IEndDragHandler
{
private Slider me;
void Awake()
{
me = gameObject.GetComponent<Slider>();
}
public void OnEndDrag(PointerEventData data)
{
me.value = 0f;
}
}
Answer by welvilindsay · May 25, 2021 at 03:35 AM
if i need slowly or smoothy?
I fired a small coroutine in OnDragEnds() that resets it smoothly.
public class SliderControl : MonoBehaviour, IEndDragHandler
{
private Slider m_slider;
void Start()
{
m_slider = GetComponent<Slider>();
}
public void OnEndDrag(PointerEventData eventData)
{
StartCoroutine(Reset());
}
private IEnumerator Reset()
{
while (Mathf.Abs(m_slider.value) > 0.1f)
{
m_slider.value = Mathf.Lerp(m_slider.value, 0, Time.deltaTime);
yield return null;
}
m_slider.value = 0f;
}
}
Your answer
Follow this Question
Related Questions
Slider handle disappears when enlarged up (4.6ui) 1 Answer
Object Rotation Sliders 1 Answer
Set Animation curve for uGUI elements 0 Answers
Remove Focus From InputField 2 Answers
Text blurred: uGUI 4.6 9 Answers