So I have a camera rendering all objects in the "map" layer onto a texture which is then assigned to a raw image in the UI which will serve as the galaxy map. I want the player to be able to mouse over the stars to activate an animation, and then click on them to select them.
Before I was using OnMouseEnter and OnMouseDown to activate these but now that the camera is rendering onto a texture they no longer work. What would be the best solution for this?
#How to raycast 2D colliders through a camera rendering onto a texture?
1 messages · Page 1 of 1 (latest)
you'll have to figure out where on the texture your mouse is in normalized coordinates, then do a manual raycast with Camera.ViewportPointToRay using those normalized texture coordinates
Not sure how to do the first bit but I'll look into it, thanks 🙂
Well I got the screen size, the size of the rectTransform, and the orthographic sizes of both cameras and have been fiddling around with the ratios
Still quite off lol
the orthographic size of the camera isn't really needed
This should get you somewhere
Actually this should get you almost entirely there: https://docs.unity3d.com/ScriptReference/RectTransformUtility.ScreenPointToLocalPointInRectangle.html