Detect when the mouse is over a sprite 2D.

I am looking for a simple way to detect which sprite in under the mouse when I mouse over it. OnMouseEnter() works with 3D physics but I couldn’t get it to work with 2D physics. So I tried doing a Physics2D ray cast but couldn’t get that to work. Any ideas?

OnMouseEnter works fine with 2D physics but it has the same requirements as a 3D object, namely that the sprite has a collider.

You need a collider component as well as a rigidbody. Most physics components in Unity don’t work without a rigidbody.

I tried this and worked out. Somehow the Collider 2D area was not fitting my sprite. Try enlarging your collider size and check out.