ScreenToWorldPoint() not working properly using a RenderTexture
Hello there!
I'm developing a 2D pixel-perfect game wihere I use 2 cameras, for the rendering with a target texture.
Camera.main.ScreenToWorldPoint() works perfectly when I don't use a target render texture but in all my tests the crosshair doesn't follow the cursor properly IF I use a target render texture with a smaller size, say 512x288.
I discovered that if I use in playmode the same exact same of the display size, there it works correctly, so I'm sure it has something to do with the scaling the screen where I display the game (16:9 doesn't work for example, only the exact width and height).
Here's how I do the crosshair script to follow the mouse.
And yeah... With render texture enabled Imagine the red arrow is actually the mouse pointer.
With render texture disabled
Thanks in advance to anyone who knows how to solve this issue.
Answer by Maverick · Aug 29, 2019 at 10:37 AM
Have same issue Unity 2019.2.2. If you use targetTexture for that camera ScreenToWorldPoint will return strange values.