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. Dismiss Notice

How do I get PointerEventData from a pointer click event? (on a Button)

Discussion in 'UGUI & TextMesh Pro' started by Ecoludologist, Jan 7, 2015.

  1. Ecoludologist

    Ecoludologist

    Joined:
    Sep 19, 2013
    Posts:
    5
    When I add an Event Trigger component to a Button, then click "Add New Event Type" -> "Pointer Click", it adds "Pointer Click (Base Event Data)" but I need PointerEventData (because I want to know if it was a left-click or right-click). I created a script with two methods:
    public void OnPointerClickWithPointerData(PointerEventData data){
    Debug.Log (data.button);​
    }
    public void OnPointerClickWithBaseData(BaseEventData data){
    Debug.Log (data);​
    }​

    but only OnPointerClickWithBaseData shows up as an option in the function dropdown.

    Thanks in advance, and sorry for what I assume MUST be something really obvious, but it's been killing me for hours.
     
  2. casimps1

    casimps1

    Joined:
    Jul 28, 2012
    Posts:
    254
    Try accepting the base data as the parameter and then casting the base data like this:

    Code (CSharp):
    1. public void OnPointerClickWithBaseData(BaseEventData data){
    2.    PointerEventData ped = ( PointerEventData )data;
    3. }
     
    Last edited: Jan 7, 2015
    Musahan17, Kiwasi and Ecoludologist like this.
  3. Ecoludologist

    Ecoludologist

    Joined:
    Sep 19, 2013
    Posts:
    5
    Thank you, casimps1, SO much! Worked perfectly. :)