본문 바로가기
개발/C#

유니티 C# 두 점 사이의 각도 구하기 간단 구현 Unity Vector2 Angle

by SPNK 2023. 3. 19.
반응형
  • 코드 작성
using UnityEngine;

public class AngleCalculator : MonoBehaviour
{
    public Transform pointA;
    public Transform pointB;

    void Start()
    {
        Vector2 direction = pointB.position - pointA.position;
        float angle = Vector2.Angle(Vector2.right, direction);
        Debug.Log("Angle between the two points: " + angle);
    }
}

 

  • 다른 예시
using UnityEngine;

public class AngleCalculator : MonoBehaviour
{
    public Transform pointA;
    public Transform pointB;

    void Start()
    {
        Vector3 direction = pointB.position - pointA.position;
        float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
        Debug.Log("Angle between the two points: " + angle);
    }
}

 

반응형

댓글