当我点击我制作的UI图像时,“void OnMouseDown()”函数不起作用!
我尝试过以下方法:
- 将其放入画布中
- 重新导入资源
- 将z设置为-1
- 将盒子碰撞器设置为正确大小
- 将盒子碰撞器设置为3D而不是2D
但以上方法都没有成功,请帮助我!
我的脚本:
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");
}
}
OnPointerDown(PointerEventData)
(实际上是新UI背后的EventSystem)。如果你的UI元素不提供开箱即用的OnPointerDown,则可以实现UnityEngine.EventSystems
中找到的IPointerDownHandler
接口(它真的很容易,只是听起来有点复杂)。 - yes