using System; using UnityEngine; public class CameraFollow : MonoBehaviour { [SerializeField] private Transform camTarget; [SerializeField] private float distance; [SerializeField] private float height; [SerializeField] private float smoothness; [SerializeField] private bool autoStart; private Vector3 _velocity; private bool _isRunning; public void StartSystem() { if (camTarget == null) { Debug.LogError("Follow target is null!"); return; } _isRunning = true; } public void StopSystem() => _isRunning = false; private void Start() { if (camTarget == null) { Debug.LogError("Follow target is null!"); return; } _isRunning = autoStart; } private void LateUpdate() { if (!_isRunning) return; var cameraPosition = Vector3.zero; var targetPosition = camTarget.position; cameraPosition.x = targetPosition.x; cameraPosition.y = targetPosition.y + height; cameraPosition.z = Mathf.Clamp(targetPosition.z - distance, -10f, 18f); transform.position = Vector3.SmoothDamp(transform.position, cameraPosition, ref _velocity, smoothness); } }