- Home /
How to convert mouse position to world coordinates
I have a 2d unity project. I cannot depend on "OnMouseExit" because overlapping 2D box colliders cause the meathod to trigger even when the mouse is inside the bounds just bacause something else is in front (which is not my intention)
I was going to manually check for the mouse exiting on every frame by using:
if(!_collider.bounds.contains(Input.MousePosition))
But this does not work because 'mouse position' is in terms of the number of pixels across the screen, and 'bounds' is in terms of "Units" relative to the origin of the scene. The camera Authographic and slides around to look at the 2D plane that the world's sprites sit on. I have no idea how many "units" fit across the screen and suspect that it would change as soon as you change the aspect ratio or screen size.
Answer by SuperMasterBlasterLaser · Nov 12, 2015 at 03:33 AM
There are multiple methods of Camera
which will help you to change coordinates of object.
Your answer
Follow this Question
Related Questions
Importing models from blender to unity Geometry and textures missing 0 Answers
How rotate a gameobject in Y axis using the mouse position at screen? 1 Answer
3D world 2D gameplay, keep player in the camera? 1 Answer
why is screen inverted (mousepos, GUI el) any fixes? 2 Answers
physics.OverlapSphere colliders 1 Answer