# ### 侧边栏

script:unityengine:classes:transform:transform.inversetransformpoint

# Transform.InverseTransformPoint 反向变换点

`JavaScript` ⇒ public function InverseTransformPoint(position: Vector3): Vector3;
`C#` ⇒public Vector3 InverseTransformPoint(Vector3 position);

#### Description 描述

Transforms position from world space to local space. The opposite of Transform.TransformPoint.

Note that the returned position is affected by scale. Use Transform.InverseTransformDirection if you are dealing with directions.

JavaScript:

```// Calculate the transform's position relative to the camera.

var cam = Camera.main.transform;
var cameraRelative = cam.InverseTransformPoint(transform.position);
if (cameraRelative.z > 0)
print ("The object is in front of the camera");
else
print ("The object is behind the camera"); ```

C#:

```using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
public Transform cam = Camera.main.transform;
public Vector3 cameraRelative = cam.InverseTransformPoint(transform.position);
void Example() {
if (cameraRelative.z > 0)
print("The object is in front of the camera");
else
print("The object is behind the camera");
}
}```

`JavaScript` ⇒public function InverseTransformPoint(x: float, y: float, z: float): Vector3;
`C#` ⇒public Vector3 InverseTransformPoint(float x, float y, float z);

#### Description 描述

Transforms the position x, y, z from world space to local space. The opposite of Transform.TransformPoint.

Note that the returned position is affected by scale. Use Transform.InverseTransformDirection if you are dealing with directions.

JavaScript:

```// Calculate the world origin relative to this transform.

relativePoint = transform.InverseTransformPoint(0, 0, 0);
if (relativePoint.z > 0)
print ("The world origin is in front of this object");
else
print ("The world origin is behind of this object"); ```

C#:

```using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
void Example() {
relativePoint = transform.InverseTransformPoint(0, 0, 0);
if (relativePoint.z > 0)
print("The world origin is in front of this object");
else
print("The world origin is behind of this object");
}
}```
script/unityengine/classes/transform/transform.inversetransformpoint.txt · 最后更改: 2016/08/02 05:37 (外部编辑)

### 页面工具 