Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Unity UI [SOLVED] Multiple Event System

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by eron82, Jan 13, 2018.

  1. eron82

    eron82

    Joined:
    Mar 10, 2017
    Posts:
    60
    How can i have 2 Event Systems in the scene so 2 players can select different UI buttons to choose their character? (like tekken for example) Thanks
     
  2. eron82

    eron82

    Joined:
    Mar 10, 2017
    Posts:
    60
    Create 2 empty objects and add this script and a Standalone Input Model on both:
    Code (csharp):
    1. using UnityEngine.EventSystems;
    2. using UnityEngine;
    3.  
    4. public class MyEventSystem : EventSystem
    5. {
    6.  
    7. protected override void OnEnable(){
    8.         base.OnEnable ();
    9. }
    10.  
    11. protected override void Update(){
    12.     EventSystem originalCurrent = EventSystem.current;
    13.     current = this;
    14.     base.Update();
    15.     current = originalCurrent;
    16. }
    17. }
    Then add these two scripts on each button selecting one event systems:
    Code (csharp):
    1. using UnityEngine.EventSystems;
    2. using UnityEngine.UI;
    3.  
    4. public class MyButton : Button
    5. {
    6.     public EventSystem eventSystem;
    7.  
    8.     protected override void Awake()
    9.     {
    10.         base.Awake ();
    11.         eventSystem = GetComponent<MyEventSystemProvider> ().eventSystem;
    12.     }
    13.  
    14.     public override void OnPointerDown(PointerEventData eventData)
    15.     {
    16.         if (eventData.button != PointerEventData.InputButton.Left)
    17.             return;
    18.  
    19.         // Selection tracking
    20.         if (IsInteractable() && navigation.mode != Navigation.Mode.None)
    21.             eventSystem.SetSelectedGameObject(gameObject, eventData);
    22.  
    23.         base.OnPointerDown(eventData);
    24.     }
    25.  
    26.     public override void Select()
    27.     {
    28.         if (eventSystem.alreadySelecting)
    29.             return;
    30.  
    31.         eventSystem.SetSelectedGameObject(gameObject);
    32.     }
    33. }
    Code (csharp):
    1. using UnityEngine.EventSystems;
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class MyEventSystemProvider : MonoBehaviour
    6. {
    7.     public EventSystem eventSystem;
    8. }
     
  3. AshMcConnell

    AshMcConnell

    Joined:
    Aug 10, 2011
    Posts:
    7
    Hi @eron82 ,

    Does this still work for you in recent versions of Unity? I'm having trouble getting it to work for my splitscreen game

    Thanks for your help!
     
    dthoma6403 likes this.
  4. dthoma6403

    dthoma6403

    Joined:
    Nov 15, 2017
    Posts:
    2
    Hey @AshMcConnell In the next few days I plan on giving this a shot if you still need help
     
  5. AshMcConnell

    AshMcConnell

    Joined:
    Aug 10, 2011
    Posts:
    7
    Only seeing this now. How did you get on? I made a very basic custom solution that allows me to move between controls on a page (only buttons and a car selector for the moment), but a "proper" solution would be great :)
     
  6. davdeo

    davdeo

    Joined:
    Aug 11, 2019
    Posts:
    1
    Hey @dthoma6403 did you already solve the problem?
    I am having the same problem as described above but i need to support 4 Players at the same time (local multiplayer character selection)
    Thank you in advance :)