Unity 5:如何检测自定义按钮和对象的触摸

时间:2015-09-01 11:02:47

标签: android unity3d touch

我正在尝试为Android和iPhone制作游戏,如果玩家点击3d胸部,他会收到一些物品。我已完成项目给予,但我无法正确检测到触摸。此外,它还必须支持多次触摸,因此付款人可以在打开胸部的同时按住移动按钮。

我既没有按钮触摸检测,也没有检测物体触摸?

他们每个人都可以拥有自己的脚本,还是将所有脚本都放在一个if语句的脚本中?

1 个答案:

答案 0 :(得分:2)

您可以在胸部对象脚本中实现IPointerClickHandler接口:

class ChestObject : MonoBehaviour, IPointerClickHandler
{
    // Your other functions ...

    void OnPointerClick(PointerEventData eventData)
    {
        //The program will run this function when you click the chest
    }
}

取决于您的需求,您还可以实施IPointerDownHandlerIPointerUpHandlerIDragHandlerIDropHandler等。这些界面附带新的UI系统,它们相当是有用的。

相关问题