HeadPos.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class HeadPos : MonoBehaviour
  5. {
  6. public Transform head;
  7. public Transform uiRoot;
  8. public Transform leftObj;
  9. public Transform rightObj;
  10. private UIMove uiMove;
  11. private void Start()
  12. {
  13. uiMove = uiRoot.GetComponent<UIMove>();
  14. }
  15. void Update()
  16. {
  17. transform.position = head.position;
  18. transform.eulerAngles = new Vector3(0, head.eulerAngles.y, 0);
  19. //if (uiMove.isMove)
  20. //{
  21. // //uiRoot.eulerAngles = transform.eulerAngles;
  22. // float dis = Vector2.Distance(new Vector2(transform.GetChild(0).position.x, transform.GetChild(0).position.z), new Vector2(uiRoot.position.x, uiRoot.position.z));
  23. // Debug.Log(dis);
  24. // if (Mathf.Abs(dis) > 0.6f)
  25. // {
  26. // float disleft = Vector3.Distance(uiRoot.position, leftObj.position);
  27. // float disright = Vector3.Distance(uiRoot.position, rightObj.position);
  28. // if (Mathf.Abs(disleft) > Mathf.Abs(disright))
  29. // {
  30. // // uiRoot.position = new Vector3(rightObj.position.x, -0.3f, rightObj.position.z);
  31. // uiRoot.RotateAround(transform.position, Vector3.up, -1);
  32. // //if(Mathf.Abs(dis) > 0.7f)
  33. // // uiRoot.position = new Vector3(rightObj.position.x, -0.3f, rightObj.position.z);
  34. // }
  35. // else
  36. // {
  37. // // uiRoot.position = new Vector3(leftObj.position.x, -0.3f, leftObj.position.z);
  38. // uiRoot.RotateAround(transform.position, Vector3.up, 1);
  39. // //if (Mathf.Abs(dis) > 0.7f)
  40. // // uiRoot.position = new Vector3(leftObj.position.x, -0.3f, leftObj.position.z);
  41. // }
  42. // }
  43. // //float y = (transform.eulerAngles.y - uiRoot.eulerAngles.y);
  44. // //Debug.Log(y);
  45. // //if (y > 10)
  46. // //{
  47. // // uiRoot.RotateAround(transform.position, Vector3.up, y);
  48. // //}
  49. // //else if (y < -30 )
  50. // //{
  51. // // uiRoot.RotateAround(transform.position, Vector3.up, transform.eulerAngles.y - 30);
  52. // //}
  53. //}
  54. }
  55. }