33 lines
824 B
C#
33 lines
824 B
C#
using System;
|
|
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;
|
|
var absTransform = new Vector3(newPosition.x, Math.Abs(newPosition.y), newPosition.z);
|
|
transform.position = Vector3.Slerp(transform.position, newPosition, smoothFactor);
|
|
}
|
|
}
|
|
}
|