如何使新的输入处理程序(IPointerDownHandler等)在非UI GameObject上工作? [英] how to make the new input handlers (IPointerDownHandler, and so on) work on non-UI GameObject?

查看:186
本文介绍了如何使新的输入处理程序(IPointerDownHandler等)在非UI GameObject上工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个这样的脚本:

I wrote a script like this:

public class LuaTap : MonoBehaviour, IPointerDownHandler, IPointerExitHandler, IPointerUpHandler {

    #region IPointerDownHandler implementation
    public void OnPointerDown (PointerEventData eventData)
    {
        Debug.Log ("down ");
    }
    #endregion

    #region IPointerExitHandler implementation
    public void OnPointerExit (PointerEventData eventData)
    {
        Debug.Log ("exit");
    }
    #endregion

    #region IPointerUpHandler implementation
    public void OnPointerUp (PointerEventData eventData)
    {
        Debug.Log ("up");
    }
    #endregion


}

将此脚本添加到Non-UI GameObject时,它不起作用. 我更喜欢新的输入处理程序,但据我所知,它仅适用于新的UI.

when this script was added to a Non-UI GameObject, it does not work. I prefer the new input handlers , but as far as I know it only works on new UI.

如何使其在非UI游戏对象上正常工作?

How to make it work on non-UI GameObjects?

推荐答案

您的游戏对象必须具有对撞机.然后,确保场景中存在事件系统和相关的Raycaster.对于UI系统,通常使用图形Raycaster ,但我认为您可能会而是需要物理Raycaster .

You game object has to have a collider. Then, ensure that you have Event System and a relevant Raycaster present in the scene. With UI system, the Graphic Raycaster is usually used, but I think that you might need Physics Raycaster instead.

这篇关于如何使新的输入处理程序(IPointerDownHandler等)在非UI GameObject上工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆