26 lines
745 B
C#
26 lines
745 B
C#
using UnityEngine;
|
|
|
|
namespace Player
|
|
{
|
|
public class Cam : MonoBehaviour
|
|
{
|
|
public float YOffset => yOffset;
|
|
[SerializeField] private float camSpeed;
|
|
[SerializeField] private float yOffset;
|
|
private Transform _player;
|
|
private Vector3 _target = new Vector3(0f, 0f, -10f);
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (_player == null)
|
|
{
|
|
_player = GameObject.FindWithTag("Player").transform;
|
|
return;
|
|
}
|
|
_target.y = Mathf.Max(_player.position.y + yOffset, 1);
|
|
transform.position = Vector3.Lerp(transform.position, _target, camSpeed * Time.deltaTime);
|
|
}
|
|
}
|
|
}
|