Version: 5.3 (switch to 5.4b)
言語English
  • C#
  • JS

スクリプト言語

好きな言語を選択してください。選択した言語でスクリプトコードが表示されます。

Transform.InverseTransformPoint

マニュアルに切り替える
public Vector3 InverseTransformPoint(Vector3 position);

パラメーター

説明

ワールド空間からローカル空間へ position を変換します。

この関数は、ローカル空間からワールド空間へ変換するために使用されるTransform.TransformPoint の逆の機能です。

返される位置情報はスケールに影響されていることに注意してください。方向に関する情報を扱う場合は Transform.InverseTransformDirection を使用します。

	// Calculate the transform's position relative to the camera.
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Transform cam; public Vector3 cameraRelative; void Start() { cam = Camera.main.transform; Vector3 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"); } }

public Vector3 InverseTransformPoint(float x, float y, float z);

パラメーター

説明

ワールド空間からローカル空間へ zzz を変換します。Transform.TransformPoint とは逆の機能になります

返される位置情報はスケールに影響されていることに注意してください。方向に関する情報を扱う場合は Transform.InverseTransformDirection を使用します。

	// Calculate the world origin relative to this transform.
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Start() { Vector3 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"); } }