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.
  2. Dismiss Notice

finger on collision object(event)

Discussion in 'Editor & General Support' started by sirblundes, May 8, 2014.

  1. sirblundes

    sirblundes

    Joined:
    Apr 19, 2014
    Posts:
    18
    hi, for mouse there are MonoBehaviour.OnMouseEnter function(event) ecc, but for fineger? in the touch?
    im doing a restart button and i need know if my finger touch it.
     
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    There are plenty of assets in the store which handle touch input, but you can use mouse events that act likes touches, or you can use the Touch class for touch input. Regardless if you are using mouse or touch, you will need to cast a ray, from touch pos, thru the screen, so on a forward vector. This ray will detect any collider it hits. If it hits said button, it will return that yes it has. And you get to chose from there, what to do.
     
  3. Mukabr

    Mukabr

    Joined:
    Jun 10, 2013
    Posts:
    61
    Code (csharp):
    1. function Update () {
    2.     if (Input.touchCount > 0  
    3.          Input.GetTouch(0).phase == TouchPhase.Moved) {
    4.                  //do stuff
    5.     }
    6. }
    this might work
     
  4. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    What Mukabr said. Plus, use the Touch API to get a touch event, then fire a ray through the screen coordinate where the touch happened, and see if that ray hits your button. (Exactly like the third example on the Input.GetTouch() API documentation page...)
     
  5. frankrs

    frankrs

    Joined:
    Aug 29, 2009
    Posts:
    300
    OnMouseDown actually works on mobile finger touches if its the only touch on the screen
     
  6. sirblundes

    sirblundes

    Joined:
    Apr 19, 2014
    Posts:
    18
    ty all this is what i need :)