世界坐标系就是unity的左手坐标系
屏幕坐标系是Game视图相机拍摄的场景坐标系,左下角(0,0),右上角(Screen.width,Screen.height),单位是像素。Z的位置是以相机的世界单位来衡量的,很多介绍都对Z一笔带过,
后面重点讲一下这个Z的含义,也就是物体距离摄像机的“距离”。
视口坐标系是将Game视图的屏幕坐标系单位化,左下角(0,0),右上角(1,1)
验证如下:
创建一个cube,和一个相机,为相机挂上脚本CameraConvert.cs
usingUnityEngine;public classCameraConvert : MonoBehaviour {publicTransform target;
Camera camera;voidStart()
{
camera= GetComponent();
Vector3 worldPos1=target.position;
Vector3 screenPos=camera.WorldToScreenPoint(worldPos1);
Vector3 worldPos2=camera.ScreenToWorldPoint(screenPos);//世界坐标系与屏幕坐标系相互转换
Debug.Log("Screen.width" +Screen.width);
Debug.Log("Screen.height" +Screen.height);
Debug.Log("target world pos1 is" +worldPos1)