UILookAtHead.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class UILookAtHead : MonoBehaviour {
  5. void Start () {
  6. }
  7. void Update () {
  8. }
  9. private Vector3 dir;
  10. private void LateUpdate()
  11. {
  12. if(LookTarget == null)
  13. {
  14. return;
  15. }
  16. //this.transform.LookAt(LookTarget, -Vector3.forward);
  17. dir = LookTarget.position - this.transform.position;
  18. //dir.x =dir.z = 0;
  19. //dir.y = 0;
  20. if(dir.Equals(Vector3.zero))
  21. {
  22. return;//排除掉0
  23. }
  24. //this.transform.rotation = Quaternion.LookRotation(dir, Vector3.up);
  25. //dir = this.transform.eulerAngles;
  26. //dir.y = 0;
  27. //this.transform.eulerAngles = dir;
  28. this.transform.LookAt(LookTarget);
  29. }
  30. private Transform LookTarget
  31. {
  32. get
  33. {
  34. return SvrManager.Instance.head.transform;
  35. //return Camera.main.transform;
  36. }
  37. }
  38. }