Camera.cameraToWorldMatrix

Switch to Manual
public Matrix4x4 cameraToWorldMatrix ;

Description

摄像机空间到世界空间的变换矩阵。(只读)

使用该属性可计算摄像机空间的特定点在世界空间中的位置。

注意,摄像机空间遵守 OpenGL 约定:摄像机前方为负 Z 轴。这与 Unity 的约定不同,在 Unity 中,摄像机前方为 正 Z 轴。


// Draw a yellow sphere in scene view at distance/
// units along camera's viewing direction.

using UnityEngine; using System.Collections;

public class ExampleClass : MonoBehaviour { public float distance = -1.0F; void OnDrawGizmosSelected() { Matrix4x4 m = Camera.main.cameraToWorldMatrix; Vector3 p = m.MultiplyPoint(new Vector3(0, 0, distance)); Gizmos.color = Color.yellow; Gizmos.DrawSphere(p, 0.2F); } }