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

OnMouseOver 2D sprite

Discussion in '2D' started by Rphysx, May 28, 2014.

  1. Rphysx

    Rphysx

    Joined:
    Mar 26, 2014
    Posts:
    54
    So It appears that you can't use the OnMouseOver function over an object with a 2Dboxcollider and I'd like to know what alternatives do we have to achieve the same results with a sprite or button, or how to implement the same behaviour with raycasts or anything which could help
     
  2. SiegfriedCroes

    SiegfriedCroes

    Joined:
    Oct 19, 2013
    Posts:
    569
    If you haven't found something yourself, this might be able to help you further:

    http://docs.unity3d.com/ScriptReference/Physics2D.OverlapPoint.html

    With that you can check if there was a collision at a certain point (mouse position). If that's the case you check if the collider you hit is the one attached to your Sprite and if so then you know the player clicked on it ;)
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Sure you can.

    --Eric