Initial commit
This commit is contained in:
39
Assets/Scripting/Khac/DisplayPosition.cs
Normal file
39
Assets/Scripting/Khac/DisplayPosition.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using UnityEngine;
|
||||
using TMPro; // Sử dụng TextMeshPro
|
||||
|
||||
public class DisplayPosition : MonoBehaviour
|
||||
{
|
||||
// Gán TextMeshProUGUI trong Inspector
|
||||
public TextMeshProUGUI positionText;
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Lấy vị trí của đối tượng
|
||||
Vector3 position = transform.position;
|
||||
float displayEulerY = NormalizeEulerAngle(-transform.eulerAngles.y); // Giữ nguyên hiển thị
|
||||
float theta = NormalizeAngle(2 * Mathf.PI - transform.eulerAngles.y * Mathf.Deg2Rad); // Công thức mới
|
||||
|
||||
// Hiển thị tọa độ x và z
|
||||
string positionInfo = $"X: {position.x:F2} \n" +
|
||||
$"Y: {position.z:F2} \n" +
|
||||
$"Theta: {displayEulerY:F2}" ;
|
||||
|
||||
// Cập nhật TextMeshProUGUI
|
||||
if (positionText != null)
|
||||
{
|
||||
positionText.text = positionInfo;
|
||||
}
|
||||
}
|
||||
public float NormalizeEulerAngle(float angleDeg)
|
||||
{
|
||||
while (angleDeg > 180f) angleDeg -= 360f;
|
||||
while (angleDeg < -180f) angleDeg += 360f;
|
||||
return angleDeg;
|
||||
}
|
||||
public float NormalizeAngle(float angleRad)
|
||||
{
|
||||
while (angleRad > Mathf.PI) angleRad -= 2 * Mathf.PI;
|
||||
while (angleRad < -Mathf.PI) angleRad += 2 * Mathf.PI;
|
||||
return angleRad;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user