- Home /
Question by
JesterHere · Nov 10, 2020 at 05:23 AM ·
uiinputbuttonmultiplayerlocal
Detect which local player clicked a button
Hi, I am using the new Unity input system and have a button in the UI. Any player is allowed to click this button but I want to know which Player it was.
I have extended the Button class from Unity so that the EventData is passed as a parameter. But how does one know which Player sent this event.
Here is my button overload:
public class ButtonEx : Button
{
// Function definition for a button click event with EventData.
[Serializable]
public class ButtonClickedExEvent : UnityEvent<BaseEventData> {}
// Event delegates triggered on click with event data.
[SerializeField]
private ButtonClickedExEvent m_onClickEx = new ButtonClickedExEvent();
public override void OnSubmit(BaseEventData p_eventData)
{
base.OnSubmit(p_eventData);
if (!IsActive() || !IsInteractable())
return;
m_onClickEx.Invoke(p_eventData);
}
public override void OnPointerClick(PointerEventData p_eventData)
{
base.OnPointerClick(p_eventData);
if (p_eventData.button != PointerEventData.InputButton.Left)
return;
m_onClickEx.Invoke(p_eventData);
}
}
Specifically how would I get the PlayerInput instance that clicked the UI button?
I reason I would like this information is so that I can determine which Player should control the next UI prompt or should be assigned the Player 1 slot.
Thanks!
Comment