Unity 2D - OnMouseDown() 不工作

Unity 2D - OnMouseDown() not working

当点击我制作的UI图片时,'void OnMouseDown()'功能不起作用! 我尝试过的事情:

  1. 列表项
  2. 放在canvas
  3. 重新导入资产
  4. 将 z 设置为 -1
  5. 设置大小合适的盒子碰撞器
  6. 将盒子碰撞器设置为 3D 而不是 2d None 对我有用,请帮助我!

我的脚本:

public class btnPlay : MonoBehaviour, IPointerDownHandler {

    Vector3 pos;

    // Update is called once per frame
    void Update () {
        pos = new Vector3 (Screen.width / 4.6f, Screen.height / 1.58f, -1f);
        transform.position = pos;
    }

    void OnPointerDown(PointerEventData p) {
        Debug.Log ("X");
        SceneManager.LoadScene ("Level");
    }
}

刚刚添加了接口 IPointerDownHandlerusing UnityEngine.EventSystems 比,我把方法改成了public。 感谢@yes 提供答案