- Home /
Place 3D plane in 2D?
Hi everybody
I'm currently placing a 2D plane with a custom shader (circular progress bar) in front of my camera. However, I would like to place it at a 2D screen position. I tried converting screen pixel positions to 3D space but I can't get it to work.
Any help would be appreciated
Answer by col000r · Jul 03, 2012 at 07:46 AM
Check out Camera.ScreenToWorldPoint() - feed it a Vector3 with the desired screen position as x/y and the desired distance to the Camera as the z.
So something like this should work: transform.position = Camera.main.ScreenToWorldPoint(new Vector3(50f, 50f, 300f));
Optionally you might want to add a transform.LookAt(Camera.main.transform);
so your circle faces the camera (if it's front is on the z axis, as it should be)
Answer by TwistedSage · Jul 03, 2012 at 08:12 AM
I've already tried this.
And for the life of me I can't get the %&#/! lookat script to work. The plane is just not visible. Debugging tells me that it's not pointing the right way. I attached a lookat script to the plane in question (The prefab have 2 sub planes) Also ScreenToWorldPoint does not place it in the correct place?!
Thanks for your help. Any other ideas? Is there some way I can get the plane to be drawn on top of all other geometry? (besides moving it)
If you want it above all other geometry at any time, use a second camera. $$anonymous$$ake a layer just for your circle and set the culling mask of the new camera to just that layer while removing that layer from the culling mask of the main camera. The new camera will now only render the circle, the main camera will render everything else. Change the depth field on the camera to deter$$anonymous$$e which one should be rendered on top.
If your plane doesn't have z looking forward, parent it to an empty gameObject, rotate it so that the plane faces forward according to the parent's orientation and apply your script to the parent ins$$anonymous$$d of the circle.
Hope this helps!
Answer by TwistedSage · Jul 03, 2012 at 12:56 PM
Hi all. Thank you for your help.
I'll have a look at it :)