浅析Unity 坐标系
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class CoordinateSystemTest : MonoBehaviour {
public Camera CurrentCamera;
void OnGUI()
{
if (CurrentCamera == null)
{
Debug.Log("相機(jī)為Null");
return;
}
GUI.Label(new Rect(300, 50, 100, 100), "坐標(biāo)變換");
GUI.Label(new Rect(100, 100, 100, 100), "1.世界坐標(biāo):");
GUI.Label(new Rect(200, 100, 200, 100), transform.position.ToString());
GUI.Label(new Rect(100, 150, 100, 100), "2.局部坐標(biāo):");
GUI.Label(new Rect(200, 150, 200, 100), transform.localPosition.ToString());
GUI.Label(new Rect(100, 200, 100, 100), "3.世界坐標(biāo)->屏幕坐標(biāo):");
GUI.Label(new Rect(200, 200, 200, 100), CurrentCamera.WorldToScreenPoint(transform.position).ToString());
GUI.Label(new Rect(100, 250, 100, 100), "4.世界坐標(biāo)->視口坐標(biāo):");
GUI.Label(new Rect(200, 250, 200, 100), CurrentCamera.WorldToViewportPoint(transform.position).ToString());
GUI.Label(new Rect(100, 300, 100, 100), "5.屏幕坐標(biāo)->視口坐標(biāo):");
GUI.Label(new Rect(200, 300, 200, 100), CurrentCamera.ScreenToViewportPoint(transform.position).ToString());
GUI.Label(new Rect(100, 350, 100, 100), "6.屏幕坐標(biāo)->世界坐標(biāo):");
GUI.Label(new Rect(200, 350, 200, 100), CurrentCamera.ScreenToWorldPoint(transform.position).ToString());
GUI.Label(new Rect(100, 400, 100, 100), "7.視口坐標(biāo)->屏幕坐標(biāo):");
GUI.Label(new Rect(200, 400, 200, 100), CurrentCamera.ViewportToScreenPoint(transform.position).ToString());
GUI.Label(new Rect(100, 450, 100, 100), "8.視口坐標(biāo)->世界坐標(biāo):");
GUI.Label(new Rect(200, 450, 200, 100), CurrentCamera.ViewportToWorldPoint(transform.position).ToString());
}
}
轉(zhuǎn)載于:https://www.cnblogs.com/Zsundy/p/9252646.html
總結(jié)
以上是生活随笔為你收集整理的浅析Unity 坐标系的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python12-并发编程
- 下一篇: 3.使用Selenium模拟浏览器抓取淘