26 lines
722 B
C#
26 lines
722 B
C#
using UnityEngine;
|
|
|
|
namespace Scampz.GameJam
|
|
{
|
|
public class CameraFollow : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private Vector3 cameraOffset;
|
|
[SerializeField]
|
|
private float _cameraYPosition = 45f;
|
|
[SerializeField]
|
|
private float _smoothTime = 0.3f;
|
|
|
|
private Vector3 velocity = Vector3.zero;
|
|
|
|
private void LateUpdate()
|
|
{
|
|
var player = GameObject.FindGameObjectWithTag("Player");
|
|
|
|
var lockedInYPosition = new Vector3(player.transform.position.x - cameraOffset.x, _cameraYPosition, player.transform.position.z - cameraOffset.z);
|
|
Vector3.SmoothDamp(transform.position, lockedInYPosition, ref velocity, _smoothTime);
|
|
transform.position = lockedInYPosition;
|
|
}
|
|
}
|
|
}
|