How do I abort a slider drag?
Hi all,
Thanks for taking a minute to have a look at my question!
I am making a simple 2D WEBGL game. There are 3 sliders on the screen, created from a prefab. The player will be given a random value to set one of the sliders to and give some number of seconds to complete the task. If the time runs out, I want any slider currently in drag to abort, pop back to its original position and have the pointer ready to drag the next slider they may click.
With the code below, that almost all happens. The problem I have having is that after an aborted drag, to start the next drag the player has to click and release on a slide handle, then click and drag. Going right for the click and drag does not work.
Any thoughts are advice is greatly appreciated!
void Start()
{
gameObject.GetComponent<ControlInterface>().LoadPossibleValues(PossibleValues);
gameObject.GetComponent<ControlInterface>().SetControlType(TypeIndex, SecondLimit);
EventTrigger trigger = GetComponent<EventTrigger>();
EventTrigger.Entry entry = new EventTrigger.Entry();
entry.eventID = EventTriggerType.Drag;
entry.callback.AddListener((data) => { OnDrag((PointerEventData)data); });
trigger.triggers.Add(entry);
}
// Update is called once per frame
void Update()
{
}
public void CancelAction()
{
stopDrag = true;
}
public void OnSliderMove()
{
byte tmp = (byte) gameObject.GetComponent<Slider>().value;
SliderValueText.GetComponent<Text>().text = tmp.ToString();
}
public void OnDrag(PointerEventData dat)
{
if (stopDrag)
{
stopDrag = false;
dat.pointerDrag = null;
SetNewValue(OldValue);
//EventSystem.current.SetSelectedGameObject(null);
dat.Reset();
}
}
public void OnDragStart()
{
OldValue = (byte) gameObject.GetComponent<Slider>().value;
}
public void OnDragEnd()
{
byte tmp = (byte) gameObject.GetComponent<Slider>().value;
gameObject.GetComponent<ControlInterface>().SetValueFromControl(tmp);
}
Your answer
Follow this Question
Related Questions
How to make or find advanced UI assets 1 Answer
How to assign slider to float: Spin, on a gameobject 1 Answer
Light intensity, UI slider does not work on Android Tablet 0 Answers
Slider graphic refuses to update with value 1 Answer
WebGL and videoplayer set frame not working in Unity 2019.4.0f1 1 Answer