반응형
- 코드 작성
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);
}
}
반응형
'개발 > C#' 카테고리의 다른 글
유니티 C# 2D 물리 점프 간단 구현 Unity Rigidbody2D Jump (0) | 2023.03.22 |
---|---|
유니티 C# 룰렛 만들기 간단 구현 Unity Roulette (0) | 2023.03.22 |
유니티 C# 플레이어를 추적하는 적 코드 간단 구현 Unity (0) | 2023.03.19 |
유니티 C# 옵저버 패턴 간단 구현 Unity Observer (0) | 2023.03.19 |
유니티 C# 특정 값을 제외한 랜덤 값 구하기 Unity Random Value Generator (0) | 2023.03.19 |
유니티 C# 블루투스 통신 간단 구현하기 Unity Bluetooth (0) | 2023.03.08 |
유니티 C# 자이로센서 간단 구현하기 (0) | 2023.03.08 |
유니티 C# 삼항 연산자 간단 구현 - Ternary operator (0) | 2023.02.18 |
댓글