LookAtCamera.cs 458 B

12345678910111213141516171819202122232425
  1. using UnityEngine;
  2. public class LookAtCamera:MonoBehaviour{
  3. public Camera lookAtCamera;
  4. public bool lookOnlyOnAwake;
  5. public void Start() {
  6. if(lookAtCamera == null){
  7. lookAtCamera = Camera.main;
  8. }
  9. if(lookOnlyOnAwake){
  10. LookCam();
  11. }
  12. }
  13. public void Update() {
  14. if(!lookOnlyOnAwake){
  15. LookCam();
  16. }
  17. }
  18. public void LookCam() {
  19. transform.LookAt(lookAtCamera.transform);
  20. }
  21. }