Version: 2018.4
LanguageEnglish
  • C#

IPointerEnterHandler

interface in UnityEngine.EventSystems


Implements interfaces:IEventSystemHandler

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Interface to implement if you wish to receive OnPointerEnter callbacks.

Use to detect when the mouse begins to hover over a certain GameObject. To detect when the mouse stops hovering over the GameObject, use 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"); } }

Public Methods

OnPointerEnter