Search Unity

Calling method with UI button.

Discussion in 'UI Toolkit' started by MegaCo, May 15, 2019.

  1. MegaCo

    MegaCo

    Joined:
    Jan 24, 2018
    Posts:
    84
    Hello, I'm trying to get a button to continually call a method via a UI button. Mainly the "respondInput" im not sure how to use the if statement to call the movement code. I've also tried the event trigger too but does not work with how the code is written. Is there a way to do this or should I rewrite it?

    Code (CSharp):
    1. void Update()
    2.     {
    3.         if (state == State.Main)
    4.         {
    5.             respondInput();
    6.         }
    7.     }
    8.  
    9. public void respondInput()
    10.     {
    11.         if (Input.GetKey(KeyCode.X))
    12.         {
    13.             respond();
    14.         }
    15.         else
    16.         {
    17.             Code
    18.             Code
    19.         }
    20.     }
    21.  
    22.     public void respond()
    23.     {
    24.         MovementCode
    25.     }
     
  2. patrickf

    patrickf

    Unity Technologies

    Joined:
    Oct 24, 2016
    Posts:
    57
    MegaCo likes this.