MiniGames/Assets/Scripts/SkyWalker/Skywalker_CameraFollow.cs
2025-09-01 00:01:33 +05:00

39 lines
986 B
C#

using UnityEngine;
public class Skywalker_CameraFollow : MonoBehaviour
{
public Transform target;
public float smoothSpeed = 0.125f;
public float minY = -5f; // camera will stop following if target falls below this Y
private Vector3 offset;
bool isGameover = false;
void Start()
{
if (target != null)
{
// Calculate initial offset
offset = transform.position - target.position;
}
}
void LateUpdate()
{
if (target != null)
{
// Only follow if player is above minY
if (target.position.y > minY)
{
Vector3 desired = target.position + offset;
transform.position = Vector3.Lerp(transform.position, desired, smoothSpeed);
}
else if(!isGameover)
{
isGameover = true;
Skywalker_GameManager.Instance.GameoverInvoker();
}
}
}
}