Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    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:
    12
    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

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    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:
    Aug 7, 2020
    Posts:
    13
    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?
     
  4. skirners1

    skirners1

    Joined:
    Sep 4, 2014
    Posts:
    9
    I’d attach an “Event System” to the button. That way you can get pressed and hold in addition to released (OnClick).