Version: 2017.3

IPointerClickHandler

interface in UnityEngine.EventSystems


实现接口:IEventSystemHandler

切换到手册

描述

要实现的接口(如果您希望接收 OnPointerClick 回调)。

使用 IPointerClickHandler 接口来处理使用 OnPointerClick 回调的单击输入。确保场景中存在事件系统,以支持单击检测。对于非 UI 游戏对象的单击检测,请确保将 PhysicsRaycaster 附加到摄像机。

using UnityEngine;
using UnityEngine.EventSystems;

public class Example : MonoBehaviour, IPointerClickHandler { //Detect if a click occurs public void OnPointerClick(PointerEventData pointerEventData) { //Output to console the clicked GameObject's name and the following message. You can replace this with your own actions for when clicking the GameObject. Debug.Log(name + " Game Object Clicked!"); } }

公共函数

OnPointerClick使用此回调可检测单击。