Unity 3d启用鼠标指针作为事件触发器的指针输入/退出 [英] Unity 3d enabling mouse pointer as a Event Trigger's pointer enter /exit

查看:157
本文介绍了Unity 3d启用鼠标指针作为事件触发器的指针输入/退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常基本的问题,那就是启用鼠标指针作为指针.我曾尝试通过一个简单的代码编写指针输入事件,该指针输入退出事件的工作方式.但是,当我使用事件触发器的PointerEnter或PointerExit事件时,不会触发操作. 我是否需要启用某些功能才能将鼠标激活为Unity 3d指针?

I have a very fundamental problem of enabling mouse cursor as a pointer. I have tried to write pointer enter events through a simple code, the pointer enter exit event work. But when I use Event Trigger's PointerEnter or PointerExit events, the actions are not fired. Do I have to enable something to activate my mouse as a Unity 3d Pointer?

推荐答案

PointerEnter PointerExit for Unity UI:

PointerEnter and PointerExit for Unity UI:

  1. Include using UnityEngine.EventSystems;在顶部.

实现PointerEnterPointerExit界面.

将脚本附加到UI的画布上.

Attach the Script to the Canvas of the UI.

PointerEnter PointerExit 用于3D对象/模型:

PointerEnter and PointerExit for 3D Object/Model:

  1. Include using UnityEngine.EventSystems;在顶部.

实现PointerEnterPointerExit界面.

将脚本附加到3D对象,并确保将2D Collider附加到该3D对象/模型.

Attach the Script to the 3D Object and make sure that a 2D Collider is attached to that 3D Object/Model.

选择Camera并将Physics Raycaster附加到相机.

PointerEnter PointerExit 用于2D对象/精灵:

PointerEnter and PointerExit for 2D Object/Sprite:

  1. Include using UnityEngine.EventSystems;在顶部.

实现PointerEnterPointerExit界面.

将脚本附加到2D对象,并确保将2D Collider附加到该2D对象/精灵.

Attach the Script to the 2D Object and make sure that a 2D Collider is attached to that 2D Object/Sprite.

选择Camera并将Physics 2D Raycaster附加到相机.

对于所有这些情况,代码都是相同的.

The code is the-same for all of these scenarios.

using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;

public class ClickTester : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
    public void OnPointerEnter(PointerEventData eventData)
    {
        Debug.Log("Pointer Enter");
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        Debug.Log("Pointer Exit");
    }
}

这篇关于Unity 3d启用鼠标指针作为事件触发器的指针输入/退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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