RoadManager.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using TMPro;
  4. using UnityEngine;
  5. public class RoadManager : MonoSingleton<RoadManager>
  6. {
  7. public GameObject StartGo;
  8. public GameObject StartGo2;
  9. public TextMeshProUGUI textMeshPro;
  10. // Start is called before the first frame update
  11. void Start()
  12. {
  13. close();
  14. }
  15. public void close()
  16. {
  17. StartGo2.SetActive(false);
  18. textMeshPro.enabled = false;
  19. }
  20. // Update is called once per frame
  21. void Update()
  22. {
  23. /*
  24. textMeshPro.transform.position = OpenXRCamera.Instance.head.position+OpenXRCamera.Instance.head.forward;
  25. textMeshPro.transform.position = new Vector3(textMeshPro.transform.position.x, textMeshPro.transform.position.y-0.3f, textMeshPro.transform.position.z);
  26. textMeshPro.transform.LookAt(OpenXRCamera.Instance.head);
  27. textMeshPro.transform.eulerAngles = new Vector3(0, textMeshPro.transform.eulerAngles.y+180, 0);*/
  28. }
  29. public void setFX(Vector3 end)
  30. {
  31. StartGo2.SetActive(true);
  32. textMeshPro.enabled = true;
  33. StartGo.transform.position =new Vector3(OpenXRCamera.Instance.head.position.x, end.y, OpenXRCamera.Instance.head.position.z);
  34. StartGo.transform.LookAt(end);
  35. StartGo.transform.localEulerAngles = new Vector3(0, StartGo.transform.localEulerAngles.y, 0);
  36. float f = StartGo.transform.eulerAngles.y - OpenXRCamera.Instance.head.eulerAngles.y;
  37. if (((f) > 0&&f<180) || (f) < -180)
  38. {
  39. textMeshPro.text = "向右看" + Vector3.Distance(StartGo.transform.position, end);
  40. if (Mathf.Abs(f) > 90)
  41. {
  42. StartGo.transform.eulerAngles = new Vector3(0, 90 + OpenXRCamera.Instance.head.eulerAngles.y, 0);
  43. StartGo.transform.localEulerAngles = new Vector3(0, StartGo.transform.localEulerAngles.y, 0);
  44. }
  45. }
  46. else
  47. {
  48. textMeshPro.text = "向左看" + Vector3.Distance(StartGo.transform.position, end);
  49. if (Mathf.Abs(f) > 90)
  50. {
  51. StartGo.transform.eulerAngles = new Vector3(0, 90 + OpenXRCamera.Instance.head.eulerAngles.y + 180, 0);
  52. StartGo.transform.localEulerAngles = new Vector3(0, StartGo.transform.localEulerAngles.y, 0);
  53. }
  54. }
  55. if (Mathf.Abs(f) < 45)
  56. {
  57. StartGo2.SetActive(false);
  58. textMeshPro.enabled = false;
  59. }
  60. else
  61. {
  62. StartGo2.gameObject.SetActive(true);
  63. textMeshPro.enabled = true;
  64. }
  65. if(Vector3.Distance(new Vector3( StartGo.transform.position.x, end.y, StartGo.transform.position.z), end)<=0.2f)
  66. {
  67. StartGo2.SetActive(false);
  68. textMeshPro.enabled = false;
  69. }
  70. StartGo2.transform.localEulerAngles = new Vector3(0, StartGo.transform.localEulerAngles.y, 0);
  71. }
  72. }