【发布时间】:2019-08-28 20:08:41
【问题描述】:
我正在尝试检查 Sprite 的触摸事件,但只能让此代码在 UI 元素上工作。我已经看到了鼠标事件的示例,但我想同时捕获鼠标和触摸,因为这个游戏将是多平台的
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
public class PlayButton : MonoBehaviour, IPointerDownHandler
{
public void OnPointerDown(PointerEventData eventData)
{
Debug.Log("play");
}
}
【问题讨论】:
-
你的精灵需要有一些
Collider,必须有一个PhysicsRaycaster连接到相机(或者如果它是一个2D游戏,则相应的2D等效项),最后需要有一个ofcEventSystem.