FollowCamera.cs 709 B

1234567891011121314151617181920212223242526272829303132
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace Funly.SkyStudio
  5. {
  6. // Moves the game component so it follows the main camera or a specific camera.
  7. [ExecuteInEditMode]
  8. public class FollowCamera : MonoBehaviour
  9. {
  10. public Camera followCamera;
  11. public Vector3 offset = Vector3.zero;
  12. void Update()
  13. {
  14. Camera followCamera;
  15. if (this.followCamera != null) {
  16. followCamera = this.followCamera;
  17. } else {
  18. followCamera = Camera.main;
  19. }
  20. if (followCamera == null) {
  21. return;
  22. }
  23. transform.position = followCamera.transform.TransformPoint(offset);
  24. }
  25. }
  26. }