Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Get value of pointerEnter - EventSystem

Discussion in 'Scripting' started by Kamil9132, Jun 12, 2015.

  1. Kamil9132

    Kamil9132

    Joined:
    May 8, 2015
    Posts:
    7
    Hey.
    How can i get value of pointerEnter of EventSystem using script?
     

    Attached Files:

  2. Polymorphik

    Polymorphik

    Joined:
    Jul 25, 2014
    Posts:
    599
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.EventSystems;
    4.  
    5. public class EventHandler : MonoBehaviour, IPointerEnterHandler {
    6.  
    7.     // Use this for initialization
    8.     void Start () {
    9.    
    10.     }
    11.    
    12.     // Update is called once per frame
    13.     void Update () {
    14.    
    15.     }
    16.  
    17.     #region IPointerEnterHandler implementation
    18.  
    19.     public void OnPointerEnter (PointerEventData eventData)
    20.     {
    21.         UnityEngine.Debug.Log(eventData.pointerCurrentRaycast.gameObject.name); // This is what you want.
    22.     }
    23.  
    24.     #endregion
    25. }
    26.  
    Hope this helps
     
    Kamil9132 likes this.
  3. Kamil9132

    Kamil9132

    Joined:
    May 8, 2015
    Posts:
    7
    Thank you for help.
     
  4. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Similar question:

    I want to know over what GameObject the pointer is.
    In other words, how do I get the info:
    PointerEnter: Background (UnityEngine.GameObject) (see screenshot from @Kamil.9132)