FollowHorizontaliHead.cs 892 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class FollowHorizontaliHead : MonoBehaviour {
  5. private void Awake()
  6. {
  7. DontDestroyOnLoad(this.gameObject);
  8. }
  9. private void LateUpdate()
  10. {
  11. RefreshPos();
  12. }
  13. //同步位置
  14. private void RefreshPos()
  15. {
  16. if (FollowTarget != null)
  17. {
  18. this.transform.position = FollowTarget.position;
  19. this.transform.eulerAngles = FollowTarget.eulerAngles.y * Vector3.up;
  20. }
  21. }
  22. private Transform FollowTarget
  23. {
  24. get {
  25. if (Camera.main != null)
  26. {
  27. //return Camera.main.transform;
  28. }
  29. if (SvrManager.Instance.head != null)
  30. {
  31. return SvrManager.Instance.head.transform;
  32. }
  33. return null;
  34. }
  35. }
  36. }