Version: 5.4 (switch to 5.5b)
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.


Suggest a change


Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.


Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.



public static function Atan2(y: float, x: float): float;
public static float Atan2(float y, float x);



Tany/x になる角度をラジアンで返します。

戻り値は X 軸と 0 で始まり (X, Y)で終わる 2D ベクトルの角度です。

注意 この関数は X が 0 であるケースを考慮していることに注意してください。 0 で除算する例外処理よりもむしろ正しい角度を返します。

// Usually you use transform.LookAt for this.
// But this can give you more control over the angle

var target : Transform;

function Update () { var relative : Vector3 = transform.InverseTransformPoint(target.position); var angle : float = Mathf.Atan2(relative.x, relative.z) * Mathf.Rad2Deg; transform.Rotate (0, angle, 0); }
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Transform target; void Update() { Vector3 relative = transform.InverseTransformPoint(target.position); float angle = Mathf.Atan2(relative.x, relative.z) * Mathf.Rad2Deg; transform.Rotate(0, angle, 0); } }