FollowHorizontaliCamera.cs 943 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. //using Vuforia;
  5. public class FollowHorizontaliCamera : MonoBehaviour
  6. {
  7. [SerializeField]
  8. private float Distance = 1.0f;
  9. private void LateUpdate()
  10. {
  11. if(Input.GetKeyDown(KeyCode.Space))
  12. {
  13. RefreshPos();
  14. }
  15. }
  16. //同步位置
  17. public void RefreshPos()
  18. {
  19. CDebug.Log("RefreshPos");
  20. if (FollowTarget != null)
  21. {
  22. this.transform.position = FollowTarget.position;
  23. this.transform.eulerAngles = FollowTarget.eulerAngles.y * Vector3.up;
  24. this.transform.position += this.transform.forward * Distance;
  25. }
  26. }
  27. private Transform FollowTarget
  28. {
  29. get
  30. {
  31. if (Camera.main != null)
  32. {
  33. return Camera.main.transform;
  34. }
  35. return null;
  36. }
  37. }
  38. }