diff options
Diffstat (limited to 'Assets/Scripts/CameraHandler.cs')
| -rw-r--r-- | Assets/Scripts/CameraHandler.cs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Assets/Scripts/CameraHandler.cs b/Assets/Scripts/CameraHandler.cs index e170503..b995d93 100644 --- a/Assets/Scripts/CameraHandler.cs +++ b/Assets/Scripts/CameraHandler.cs @@ -8,10 +8,11 @@ namespace DS { public class CameraHandler : MonoBehaviour { + public Transform player; // 跟踪目标(如玩家角色) + // ========== 公开引用 ========== [Header("Camera Transforms")] public Transform cameraTransform; // 摄像机 Transform(子物体) - public Transform targetTransform; // 跟踪目标(如玩家角色) public Transform cameraPivotTransform; // 摄像机枢轴 Transform(用于俯仰旋转) // ========== 私有引用与状态 ========== @@ -57,6 +58,12 @@ namespace DS _defaultPosition = cameraTransform.localPosition.z; // 记录默认 Z 距离 // 忽略层级:8(玩家)、9、10;使用位取反运算 _ignoreLayers = ~(1 << 8 | 1 << 9 | 1 << 10); + + // 自动绑定 PlayerLocomotion + if (player == null) + { + player = FindObjectOfType<PlayerLocomotion>().transform; + } } // ==================================================================== @@ -97,7 +104,7 @@ namespace DS // 使用 SmoothDamp 平滑移动到目标位置 Vector3 targetPosition = Vector3.SmoothDamp( _myTransform.position, - targetTransform.position, + player.position, ref cameraFollowVelocity, delta / followSpeed); |
