Unity 3D onClick 或 Input.touchCount 不工作

Unity 3D onClick or Input.touchCount not working

我们有个小问题。当我们使用

 if (Input.touchCount > 0)
    Debug.Log(Input.touchCount.ToString());

我们总是得到零。怎么了?

或者当我们使用

public class ExampleClass : MonoBehaviour {
    void OnMouseDown() {
        Application.LoadLevel("SomeLevel");
    }
}

它也不起作用。我们只想在任何地方单击时跳到另一个场景。

OnMouseDown is called when the user has pressed the mouse button while over the GUIElement or Collider.

如果我正确理解您的问题,您需要在 Update 函数中使用 Input.touchCount。喜欢:

void Update() {
   if (Input.touchCount > 0)
       Debug.Log(Input.touchCount.ToString());     
}

创建一个按钮并使其不可见并添加此功能

using UnityEngine;
using System.Collections;

public class btnAction : MonoBehaviour {

  public void PlaybtnClicked(string SceneNumber){
      Application.LoadLevel (SceneNumber);
  }

}

别忘了使按钮足够大以覆盖整个屏幕。它会解决你的问题

这件事发生在我身上:我的游戏停止识别触摸输入,似乎在安装输入系统后就可以了。 我关闭了 Unity,删除了项目中的 Library 文件夹,然后重新启动了 Unity。触摸输入现在又可以工作了。