25 lines
675 B
C#
25 lines
675 B
C#
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// Smooth top/back camera that keeps the player and generated path visible.
|
|
/// </summary>
|
|
public class CameraFollow : MonoBehaviour
|
|
{
|
|
public Transform target;
|
|
public Vector3 offset = new Vector3(0f, 8f, -8f);
|
|
public float followSpeed = 6f;
|
|
public float lookHeight = 1f;
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (target == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Vector3 desiredPosition = target.position + offset;
|
|
transform.position = Vector3.Lerp(transform.position, desiredPosition, followSpeed * Time.deltaTime);
|
|
transform.LookAt(target.position + Vector3.up * lookHeight);
|
|
}
|
|
}
|