0
\$\begingroup\$

I have a panel with 10 sub panels in it. I am using Event Trigger to intercept the messages from these sub panels OnPointerDown event calls some function in the some script of an Game Object.

Is there a way to know in the function which of the sub panels was clicked. That way I can use the same function for all the sub panels or should I make individual function for each of the sub panels.

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$
PointerEventData.pointerPress returns The `GameObject` that received the OnPointerDown. 

So you can do something like this :

OnPointerDown(PointerEventData e)
{
  Debug.Log(e.pointerPress.name);
}

Edit to answer the question in the comments. You can make the function you are calling in the event trigger require a BaseEventData argument. Then you can cast that argument to a PointerEventData like in the following example :

public void test1(BaseEventData data)
    {
        PointerEventData e = data as PointerEventData;
        Debug.Log(e.pointerPress.name);
    }
\$\endgroup\$
1
  • \$\begingroup\$ Thanks for reply. Lets say my panel name is Panel1 and the function that is called in Pointer Down Event Trigger is test1(). How to find out from within test1() which panel called the function. \$\endgroup\$ Commented Mar 2, 2017 at 22:17
0
\$\begingroup\$

The easiest way I see is, To attach a small script on each one, when clicked it will call a function and pass as parameter an index indicating which sub panel was clicked.

There is probably a better/more optimized way to go about it if you have many panels, but in the range of 0-10 I think it can work well.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .