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

スクリプト言語

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

Vector3.Angle

マニュアルに切り替える
public static float Angle(Vector3 from, Vector3 to);

パラメーター

from このベクトルから角度を計算します
to このベクトルまでの角度を計算します

説明

2 点間( fromto )の角度を返します

角度は常に 2 つのベクトル間の 鋭角 を返します。(すなわち、必ず角度は 180 度未満)

using UnityEngine;

public class AngleExample : MonoBehaviour { public Transform target;

// prints "close" if the z-axis of this transform looks // almost towards the target

void Update () { Vector3 targetDir = target.position - transform.position; float angle = Vector3.Angle( targetDir, transform.forward );

if( angle < 5.0f ) print( "close" ); } }