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 void Start()
  11. {
  12. // uiMove = uiRoot.GetComponent<UIMove>();
  13. }
  14. void Update()
  15. {
  16. transform.position = head.position;
  17. transform.eulerAngles = new Vector3(0, head.eulerAngles.y, 0);
  18. //if (uiMove.isMove)
  19. //{
  20. // //uiRoot.eulerAngles = transform.eulerAngles;
  21. // float dis = Vector2.Distance(new Vector2(transform.GetChild(0).position.x, transform.GetChild(0).position.z), new Vector2(uiRoot.position.x, uiRoot.position.z));
  22. // Debug.Log(dis);
  23. // if (Mathf.Abs(dis) > 0.6f)
  24. // {
  25. // float disleft = Vector3.Distance(uiRoot.position, leftObj.position);
  26. // float disright = Vector3.Distance(uiRoot.position, rightObj.position);
  27. // if (Mathf.Abs(disleft) > Mathf.Abs(disright))
  28. // {
  29. // // uiRoot.position = new Vector3(rightObj.position.x, -0.3f, rightObj.position.z);
  30. // uiRoot.RotateAround(transform.position, Vector3.up, -1);
  31. // //if(Mathf.Abs(dis) > 0.7f)
  32. // // uiRoot.position = new Vector3(rightObj.position.x, -0.3f, rightObj.position.z);
  33. // }
  34. // else
  35. // {
  36. // // uiRoot.position = new Vector3(leftObj.position.x, -0.3f, leftObj.position.z);
  37. // uiRoot.RotateAround(transform.position, Vector3.up, 1);
  38. // //if (Mathf.Abs(dis) > 0.7f)
  39. // // uiRoot.position = new Vector3(leftObj.position.x, -0.3f, leftObj.position.z);
  40. // }
  41. // }
  42. // //float y = (transform.eulerAngles.y - uiRoot.eulerAngles.y);
  43. // //Debug.Log(y);
  44. // //if (y > 10)
  45. // //{
  46. // // uiRoot.RotateAround(transform.position, Vector3.up, y);
  47. // //}
  48. // //else if (y < -30 )
  49. // //{
  50. // // uiRoot.RotateAround(transform.position, Vector3.up, transform.eulerAngles.y - 30);
  51. // //}
  52. //}
  53. }
  54. }