IPointerEnterHandler

interface in UnityEngine.EventSystems


实现接口:IEventSystemHandler

切换到手册

描述

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

用于检测鼠标何时开始悬停在某个游戏对象上。要检测鼠标何时停止悬停在游戏对象上,请使用 IPointerExitHandler

//Attach this script to the GameObject you would like to have mouse hovering detected on
//This script outputs a message to the Console when the mouse pointer is currently detected hovering over the GameObject and also when the pointer leaves.

using UnityEngine; using UnityEngine.EventSystems;

public class Example : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler { //Detect if the Cursor starts to pass over the GameObject public void OnPointerEnter(PointerEventData pointerEventData) { //Output to console the GameObject's name and the following message Debug.Log("Cursor Entering " + name + " GameObject"); }

//Detect when Cursor leaves the GameObject public void OnPointerExit(PointerEventData pointerEventData) { //Output the following message with the GameObject's name Debug.Log("Cursor Exiting " + name + " GameObject"); } }

公共函数

OnPointerEnter
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961