Version: 2022.3
언어: 한국어
public static float Atan2 (float y, float x);

설명

Returns the angle in radians whose Tan is y/x.

Return value is the angle between the x-axis and a 2D vector starting at zero and terminating at (x,y).

Note: This function takes account of the cases where x is zero and returns the correct angle rather than throwing a division by zero exception.

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

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); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961