言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

Transform.LookAt

Switch to Manual
public function LookAt(target: Transform, worldUp: Vector3 = Vector3.up): void;

Parameters

target 向ける対象オブジェクト
worldUp 上方ベクトルを指定

Description

対象のTransformを設定し、その方向へと向かせます

worldUp ベクトルが上方ベクトルの方向となり、回転を変更します。 worldUp パラメータを省略した場合、関数はワールドのY軸を使用します。 worldUp はベクトルのヒントのためだけに使用します。前方ベクトルが worldUp に対して垂直である場合、 回転の上方ベクトルは worldUp ベクトルとのみ一致します。

	// This complete script can be attached to a camera to make it 
	// continuously point at another object.
	
	// The target variable shows up as a property in the inspector. 
	// Drag another object onto it to make the camera look at it.
	var target : Transform; 
	
	// Rotate the camera every frame so it keeps looking at the target 
	function Update() {
		transform.LookAt(target);
	}
public function LookAt(worldPosition: Vector3, worldUp: Vector3 = Vector3.up): void;

Parameters

worldPosition 向かせるポイント
worldUp 上方ベクトルを指定

Description

/worldPosition/ の方向へと向かせます

worldUp ベクトルが上方ベクトルの方向となり、回転を変更します。 worldUp パラメータを省略した場合、関数はワールドのY軸を使用します。 worldUp はベクトルのヒントのためだけに使用します。前方ベクトルが worldUp に対して垂直である場合、 回転の上方ベクトルは worldUp ベクトルとのみ一致します。

	// Point the object at the world origin
	transform.LookAt(Vector3.zero);