调用Unity自带接口即可,代码如下:
public class upSpeed : MonoBehaviour,IPointerDownHandler,IPointerUpHandler
{
// Start is called before the first frame update
private void Awake()
{
this.gameObject.GetComponent<Button>();
}
// Update is called once per frame
public void OnPointerDown(PointerEventData eventData)
{
//TODO
}
public void OnPointerUp(PointerEventData eventData)
{
//TODO
}
}
其中OnPointerDown为持续按下检测,OnPointerUp为持续抬起检测。