23 lines
565 B
C#
23 lines
565 B
C#
using UnityEngine;
|
|
|
|
public class CameraFollow : MonoBehaviour
|
|
{
|
|
public Transform target; // 角色的Transform组件
|
|
public Vector3 offset; // 摄像机相对于角色的偏移量
|
|
public float smoothSpeed = 0.125f; // 摄像机移动的平滑速度
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (target == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Vector3 desiredPosition = target.position + offset;
|
|
transform.position = Vector3.Lerp(
|
|
transform.position,
|
|
desiredPosition,
|
|
smoothSpeed);
|
|
}
|
|
}
|