FollowCenterCamera.cs 720 B

123456789101112131415161718192021222324252627
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class FollowCenterCamera : MonoBehaviour
  5. {
  6. public GameObject cameraObj;
  7. // Start is called before the first frame update
  8. void Start()
  9. {
  10. DontDestroyOnLoad(this.gameObject);
  11. }
  12. Queue<Vector3> posq = new Queue<Vector3>();
  13. Queue<Vector3> eulq = new Queue<Vector3>();
  14. // Update is called once per frame
  15. void Update()
  16. {
  17. if(posq.Count>3)
  18. {
  19. this.transform.position = posq.Dequeue();
  20. this.transform.eulerAngles = eulq.Dequeue();
  21. }
  22. posq.Enqueue(cameraObj.transform.position);
  23. eulq.Enqueue(cameraObj.transform.eulerAngles);
  24. }
  25. }