31 lines
715 B
C#
31 lines
715 B
C#
using UnityEngine;
|
|
|
|
namespace Scampz.GameJam
|
|
{
|
|
public class CameraFollow : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private Transform targetObject;
|
|
[SerializeField]
|
|
private Vector3 cameraOffset;
|
|
[SerializeField]
|
|
private float smoothFactor = 0.5f;
|
|
[SerializeField]
|
|
private bool lookAtTarget = false;
|
|
|
|
private void Start()
|
|
{
|
|
cameraOffset = transform.position - targetObject.transform.position;
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (lookAtTarget)
|
|
transform.LookAt(targetObject);
|
|
|
|
var newPosition = targetObject.transform.position + cameraOffset;
|
|
transform.position = Vector3.Slerp(transform.position, newPosition, smoothFactor);
|
|
}
|
|
}
|
|
}
|