- Home /
 
 
               Question by 
               MegaTDog · May 20, 2020 at 11:00 AM · 
                uiinputbuttoncontrollerxboxcontroller  
              
 
              Help Needed: How to Use Input Manager on UI Button
Hi All, 
I am trying to get my UI / Inventory to work with directional arrows and keys (with potential for controller support) 
I managed to get Left Click, Middle Click and Right Click to work on a UI Button by applying the following script that I found online:
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.EventSystems;
 using UnityEngine.Events;
 
 public class RightClick : MonoBehaviour, IPointerClickHandler
 {
 
     public UnityEvent leftClick;
     public UnityEvent middleClick;
     public UnityEvent rightClick;
 
     public void OnPointerClick(PointerEventData eventData)
     {
         if (eventData.button == PointerEventData.InputButton.Left)
             leftClick.Invoke();
         else if (eventData.button == PointerEventData.InputButton.Middle)
             middleClick.Invoke();
         else if (eventData.button == PointerEventData.InputButton.Right)
             rightClick.Invoke();
     }
 
 }
 
               
 How would I edit this script to support the Input Module? 
I tried the following but it "Activated" every button in my scene whenever I pressed cancel or submit:
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.EventSystems;
 using UnityEngine.Events;
 
 public class RightClick : MonoBehaviour, IPointerClickHandler
 {
 
     public UnityEvent leftClick;
     public UnityEvent middleClick;
     public UnityEvent rightClick;
     public UnityEvent submit;
     public UnityEvent cancel;
 
     public void OnPointerClick(PointerEventData eventData)
     {
         if (eventData.button == PointerEventData.InputButton.Left)
             leftClick.Invoke();
         else if (eventData.button == PointerEventData.InputButton.Middle)
             middleClick.Invoke();
         else if (eventData.button == PointerEventData.InputButton.Right)
             rightClick.Invoke();
     }
 
     public void Update()
     {
         if(Input.GetButton("Submit"))
         {
             submit.Invoke();
         }
         else if (Input.GetButton("cancel"))
         {
             cancel.Invoke();
         }
     }
 }
 
               
 Console log showing the buttons all being activated many times 
 If someone could help me get this working I would be extremely happy. My current inventory works great with a mouse but trying to get it to support controller input has been impossible
 Thank you
 
                 
                2020-05-20-20-44-17-window.png 
                (239.3 kB) 
               
 
              
               Comment
              
 
               
              Your answer