CameraFollower.cs 1023 B

123456789101112131415161718192021222324252627282930
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace SC.XR.Unity {
  5. public class CameraFollower : FollowerBase {
  6. bool isInit = false;
  7. protected override void OnEnable() {
  8. base.OnEnable();
  9. isInit = false;
  10. }
  11. protected override void Follow() {
  12. if (SvrManager.Instance?.head == null) {
  13. return;
  14. }
  15. if (isInit == false) {
  16. transform.position = CalculateWindowPosition(SvrManager.Instance.head);
  17. transform.rotation = CalculateWindowRotation(SvrManager.Instance.head);
  18. isInit = true;
  19. }
  20. transform.position = Vector3.Lerp(transform.position, CalculateWindowPosition(SvrManager.Instance.head), WindowFollowSpeed * Time.deltaTime);
  21. transform.rotation = Quaternion.Slerp(transform.rotation, CalculateWindowRotation(SvrManager.Instance.head), WindowFollowSpeed * Time.deltaTime);
  22. }
  23. }
  24. }