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

Detect selection via touch or mouse click on a GameObject/Sprite?

Discussion in '2D' started by BusyCat, Jan 24, 2015.

  1. BusyCat

    BusyCat

    Joined:
    Jan 9, 2015
    Posts:
    37
    Hi. I've been searching and watching some of the new 4.6 videos, etc. It isn't clear to me what the best way to handle this is.

    Put simply, I am going to have a few 2D sprite objects on the screen. I want to create a unified way of determining if a character is either clicked (mouse) or touched/tapped regardless of whether it is running on a tablet or on a PC/Mac.

    Can someone point me in the right direction? Not asking for anyone to do my homework for me.

    Thanks!
     
  2. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,256
    Found this that may help. Script only needs to be in the scene somewhere, they recommend the camera. Then you can universally use OnMouseDown for touches as well as mouse clicks. You could even extend it for all the other functionality like OnMouseMove and all that.
     
    theANMATOR2b likes this.
  3. BusyCat

    BusyCat

    Joined:
    Jan 9, 2015
    Posts:
    37
    Excellent! Thank you for providing this.

    Best,

    NJ