Hi,
I want to create a touch sensiteive UI Button. What I mean is, I would like to detect tap, drag, up… etc.
Tho the scripting pages list OnMouseDrag() etc under the UI Button, if I place…
public OnMouseDrag(){
print("dragging");
}
…nothing occurs.
I added
using UnityEngine.UI;
… still no luck.
I googled about, this chap created a wrapper…
public class UIInput : MonoBehaviour, IPointerDownHandler
{
public List<Action<PointerEventData>> OnMouseDownListeners=new List<Action<PointerEventData>>();
public void OnPointerDown(PointerEventData eventData)
{
foreach(var callback inOnMouseDownListeners)
{
callback(eventData);
}
}
public void AddOnMouseDownListener(Action<PointerEventData> action ){
OnMouseDownListeners.Add(action);
}
}
…but i don’t understand it, and I am traditionally hesitant to add code I do not get.
So, is this wrapper above the way to go? What is the best way to achieve a dynamic, sensitive button? I realize I could just monitor in Update, but I was hoping for a more dynamic system.