first commit
This commit is contained in:
25
Assets/Scripts/Asrtronaut/CameraFollow.cs
Normal file
25
Assets/Scripts/Asrtronaut/CameraFollow.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraFollow : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Transform _target;
|
||||
[SerializeField] private float _smoothSpeed = 5f;
|
||||
|
||||
private float _offsetY;
|
||||
private float _minY;
|
||||
|
||||
void Start()
|
||||
{
|
||||
_offsetY = transform.position.y - _target.position.y;
|
||||
_minY = transform.position.y;
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
float targetY = Mathf.Max(_target.position.y + _offsetY, _minY);
|
||||
Vector3 newPos = new Vector3(transform.position.x, targetY, transform.position.z);
|
||||
transform.position = Vector3.Lerp(transform.position, newPos, Time.deltaTime * _smoothSpeed);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user