与ARCore合作在UNITY中创建指南针。 播放器是AR核心设备:第一人称相机。 任何人都可以解决始终获得0的问题。 Click here for Screenshot
using UnityEngine.UI;
using UnityEngine;
public class Compass : MonoBehaviour
{
public RawImage CompassImage;
public Transform Player;
public Text CompassDirectionText;
public void Update()
{
CompassImage.uvRect = new Rect(Player.localEulerAngles.y / 360, 0, 1, 1);
Vector3 forward = Player.transform.forward;
forward.y = 0;
float headingAngle = Quaternion.LookRotation(forward).eulerAngles.y;
headingAngle = 5 * (Mathf.RoundToInt(headingAngle / 5.0f));
int displayangle;
displayangle = Mathf.RoundToInt(headingAngle);
CompassDirectionText.text = headingAngle.ToString ();
}
}