19 lines
523 B
C#
19 lines
523 B
C#
using UnityEngine;
|
|
|
|
public class LookAtCamera : MonoBehaviour {
|
|
[SerializeField] private bool invert;
|
|
private Transform cameraTransform;
|
|
|
|
private void Awake() => cameraTransform = Camera.main.transform;
|
|
|
|
private void LateUpdate() {
|
|
if (invert) {
|
|
Vector3 dirToCamera = (cameraTransform.position - transform.position).normalized;
|
|
transform.LookAt(transform.position + dirToCamera * -1);
|
|
}
|
|
else {
|
|
transform.LookAt(cameraTransform);
|
|
}
|
|
}
|
|
}
|