RoadManager.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using TMPro;
  4. using UnityEngine;
  5. public class RoadManager : MonoBehaviour
  6. {
  7. public GameObject EndGo;
  8. public GameObject StartGo;
  9. public TextMeshProUGUI textMeshPro;
  10. // Start is called before the first frame update
  11. void Start()
  12. {
  13. }
  14. // Update is called once per frame
  15. void Update()
  16. {
  17. textMeshPro.transform.position = OpenXRCamera.Instance.head.position+OpenXRCamera.Instance.head.forward;
  18. textMeshPro.transform.position = new Vector3(textMeshPro.transform.position.x, textMeshPro.transform.position.y-0.3f, textMeshPro.transform.position.z);
  19. textMeshPro.transform.LookAt(OpenXRCamera.Instance.head);
  20. textMeshPro.transform.eulerAngles = new Vector3(0, textMeshPro.transform.eulerAngles.y+180, 0);
  21. StartGo.transform.LookAt(EndGo.transform);
  22. StartGo.transform.eulerAngles = new Vector3(90, StartGo.transform.eulerAngles.y,0);
  23. float f = StartGo.transform.eulerAngles.y - OpenXRCamera.Instance.head.eulerAngles.y;
  24. if ((f)>0|| (f) < -180)
  25. {
  26. textMeshPro.text = "ÏòÓÒ¿´";
  27. if (Mathf.Abs(f) > 90)
  28. {
  29. StartGo.transform.eulerAngles = new Vector3(90, 90+ OpenXRCamera.Instance.head.eulerAngles.y, 0);
  30. }
  31. }
  32. else
  33. {
  34. textMeshPro.text = "Ïò×ó¿´";
  35. if (Mathf.Abs(f) > 90)
  36. {
  37. StartGo.transform.eulerAngles = new Vector3(90, 90 + OpenXRCamera.Instance.head.eulerAngles.y+180, 0);
  38. }
  39. }
  40. if(Mathf.Abs(f) < 45)
  41. {
  42. textMeshPro.enabled=false;
  43. }else
  44. {
  45. textMeshPro.enabled = true;
  46. }
  47. }
  48. }