Convert between screen and world coordinates in Unity
Project a scene object to screen pixels, then use camera depth or a ground plane to recover a world position.
Place a label above an object
In the Game view, use the same camera that renders the object. The lower-left pixel is (0, 0). The returned z is camera-space depth in world units. A point behind the camera has negative depth. For a screen-space overlay Canvas, place the label at the projected pixel position.
Try a round trip
Attach this script to a GameObject and assign the camera and target. With a full-screen 800 × 600 camera at the origin facing +Z, a target at (0, 0, 10) projects to approximately (400, 300, 10). Keep the returned z to recover the target.
CoordinateExample.cs
using UnityEngine;
public class CoordinateExample : MonoBehaviour
{
public Camera view;
public Transform target;
void Start()
{
Vector3 pixel = view.WorldToScreenPoint(target.position);
Vector3 restored = view.ScreenToWorldPoint(pixel);
Debug.Log($"Screen {pixel}, world {restored}");
}
public bool TryGroundPoint(Vector2 screenPixel, out Vector3 point)
{
Ray ray = view.ScreenPointToRay(screenPixel);
Plane ground = new Plane(Vector3.up, Vector3.zero);
if (ground.Raycast(ray, out float distance))
{
point = ray.GetPoint(distance);
return true;
}
point = default;
return false;
}
}Place a marker on the ground
A screen point alone describes a ray. Intersect it with the world plane y = 0. Pass the pointer position in Game-view screen pixels. A parallel ray or a plane behind the ray has no forward hit.
Camera.WorldToScreenPoint · Camera.ScreenToWorldPoint · Camera.ScreenPointToRay