Search Unity

Help with touch input

Discussion in 'Scripting' started by ajsnarr98, Oct 10, 2015.

  1. ajsnarr98

    ajsnarr98

    Joined:
    Jun 15, 2015
    Posts:
    73
    I know that in unity one can have UI buttons to detect touch input, and can also get general click and release input, but is there a way to get more specific touch input?

    Mainly I want to know if there is a way to detect if someone clicks on a game object (like a sprite) and if there is a way to allow users to pinch the screen in a certain area to zoom in or out in that area (I know how to do the zooming just not how to detect the area-specific pinch).

    Can anyone help me with this? Thanks in advance :)
     
  2. Yash987654321

    Yash987654321

    Joined:
    Oct 22, 2014
    Posts:
    729
    use camera.screenPointToRay and touch.position for detecting touch on objects. How to do that will be your homework or a Google search.
    For pinch check if more that 1 touch is being made. record the start distance between them and when one is released check the distance again. Its again your homework
    Edit- for a certain area... check if your x and y of both touches end/start in range of that area for you want to detect touch in top left 100 pixels check if touch.position.x is lesser than 100 and same for touch.position.y you could also check if a object is being touched which is a easier method.
     
    mmk likes this.
  3. ajsnarr98

    ajsnarr98

    Joined:
    Jun 15, 2015
    Posts:
    73
    Ok thanks man!