As I stated, changing the z position changed nothing.
Probably since I’m using an orthographic camera in 2D space and not in 3D space as in the documentation.
ScreenToWorldpoint is giving me the same values, except for the z pos, however since it’s 2D this doesnt make a difference.
I’ve tried ScreenToViewport too and it’s giving me (0,0,0 and (1,1,0) as expected, so the input values are at least correct.
But when I’m trying to convert either to Worldpoint it breaks.
The code below will create a quad and place it in the top right corner of the screen. In orthographic mode the quad will be very small.
Vector3 topRight = Camera.main.ViewportToWorldPoint(new Vector3(1, 1, Camera.main.nearClipPlane));
GameObject obj=GameObject.CreatePrimitive(PrimitiveType.Quad);
obj.transform.position=topRight+Camera.main.transform.forward*0.02f; // Position the quad and push it forward slightly so it doesn't get clipped
obj.transform.localScale=Vector3.one*0.1f;
I discovered the problem.
I’ve been using a 2nd camera to create a render texture, for some reason it was tagged as main camera too (I don’t know why since newly created cameras are per default untagged), after changing the tag everything worked.