Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

how do you code unity ui button touch controls to recieve an input?

Discussion in 'Input System' started by rory_chang05, Aug 1, 2020.

  1. rory_chang05

    rory_chang05

    Joined:
    May 16, 2020
    Posts:
    9
    I have a right, left and up button on the screen (its a 2D game). I am trying to figure out how to write a script so that when the user clicks the buttons, they receive the input and either move the player right left or up. I have watched some tutorials on youtube but they are from a couple of years ago and are out of date and don't work for me. Could anyone send me a script or tell me how to code it (c#) so that it can recognise the touch input?
     
  2. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,387
    Touch response for UI buttons is the same as for mouse input. Simply put a handler in place for the "On Click" event of the button.
     
    rory_chang05 likes this.
  3. cube_sniper24

    cube_sniper24

    Joined:
    Friday
    Posts:
    1
    i am trying to make a homescreen, i am new to unity, so can you post an example script as how to do an on click function?
     
unityunity