Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


ScreenToViewportPoint(Vector3)

Transforms position from screen space into viewport space.
Read time 1 minuteLast updated 13 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule
public Vector3 ScreenToViewportPoint(Vector3 position)

Parameters

position

Returns

Type

Description

Vector3

Remarks

Screen space is defined in pixels. The bottom-left of the screen is (0,0); the right-top is (Camera.pixelWidth,Camera.pixelHeight). The z position is in world units from the camera.
Viewport space is normalized and relative to the camera. The bottom-left of the camera is (0,0); the top-right is (1,1). The z position is in world units from the camera.

Examples

using UnityEngine;public class Example : MonoBehaviour{ void Update() { transform.position = Camera.main.ScreenToViewportPoint(Input.mousePosition); }}