Files
gold_dolphin/unity/Assets/2.5D Engine/Scripts/CameraFollow.cs
T
2026-07-04 12:15:13 +08:00

25 lines
1.0 KiB
C#

using UnityEngine;
namespace IndianOceanAssets.Engine2_5D
{
// This class makes the camera follow a target transform with a specified offset.
public class CameraFollow : MonoBehaviour
{
// The target Transform that the camera will follow.
[SerializeField] private Transform target;
// The positional offset from the target.
[SerializeField] private Vector3 offset;
[Tooltip("跟随平滑度(值越大跟随越紧密,10=几乎即时跟随)")]
[SerializeField] private float followSmoothness = 20f;
// Called once per frame — 使用 LateUpdate 确保在 FixedUpdate 物理移动之后执行,
// 与 LightMaskSystem 的 LateUpdate 同步,避免光照抖动
private void LateUpdate()
{
// If a target is assigned, smoothly move the camera towards the target's position plus the offset.
if (target)
transform.position = Vector3.Lerp(transform.position, target.position + offset, Time.deltaTime * followSmoothness);
}
}
}