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.

[SOLVED]How click GUILayout.Button with gamepad

Discussion in 'Immediate Mode GUI (IMGUI)' started by HuangWM, Aug 2, 2019.

  1. HuangWM

    HuangWM

    Joined:
    Nov 3, 2015
    Posts:
    45
    I use OnGUI to draw DebugPanel, Use the mouse to work correctly, but gamepad cant click.
    upload_2019-8-2_11-54-51.png
     
  2. HuangWM

    HuangWM

    Joined:
    Nov 3, 2015
    Posts:
    45
    Code (CSharp):
    1. private void OnGUI()
    2. {
    3.     if (Event.current.type == EventType.Repaint)
    4.     {
    5.        
    6.         if (gamepadDown)
    7.         {
    8.             Event.current.mousePosition = virtual cursor position
    9.             gamepadDown = false;
    10.             Event.current.type = EventType.MouseDown;
    11.         }
    12.         else if (gamepadUp)
    13.         {
    14.             Event.current.mousePosition = virtual cursor position
    15.             gamepadUp = false;
    16.             Event.current.type = EventType.MouseUp;
    17.         }
    18.     }
    19. }