我正在使用Unity 5.2 UI。我正在为iOS开发游戏。我有一个自定义键盘。我想将这些功能添加到del / backspace键,这样当我按住del键超过2秒时,它会删除整个单词而不是单个字母,单击它就会删除它。我如何实现这一目标?
答案 0 :(得分:0)
使用UGUI事件,您可以创建如下所示的脚本并将其附加到您的按钮:
using UnityEngine;
using UnityEngine.EventSystems;
public class LongPress : MonoBehaviour, IPointerDownHandler, IPointerUpHandler {
private bool isDown;
private float downTime;
public void OnPointerDown(PointerEventData eventData) {
this.isDown = true;
this.downTime = Time.realtimeSinceStartup;
}
public void OnPointerUp(PointerEventData eventData) {
this.isDown = false;
}
void Update() {
if (!this.isDown) return;
if (Time.realtimeSinceStartup - this.downTime > 2f) {
print("Handle Long Tap");
this.isDown = false;
}
}
}