小编Nic*_*Nic的帖子

长时间按和随机时间值

我要在触摸屏上长按几秒钟后触发一个事件。我正在尝试通过以下代码实现此目标。问题在于,以某种方式经过的时间是随机的。

private float timePressed = 0.0f;
private float timeLastPress = 0.0f;
public  float timeDelayThreshold = 2.0f;

void Update() {
  checkForLongPress(timeDelayThreshold);
}

void checkForLongPress(float tim) {
  for (int i = 0; i < Input.touchCount; i++)
  {
    if (Input.GetTouch(0).phase == TouchPhase.Began)
    {
      // If the user puts her finger on screen...
      Debug.Log("Touch start");
      timePressed = Time.time - timeLastPress;
    }

    if (Input.GetTouch(0).phase == TouchPhase.Ended)
    {
      // If the user raises her finger from screen
      timeLastPress = Time.time;
      Debug.Log("Releasing Touch");
      Debug.Log("Time passed --> " …
Run Code Online (Sandbox Code Playgroud)

touch unity-game-engine

0
推荐指数
1
解决办法
46
查看次数

标签 统计

touch ×1

unity-game-engine ×1