using UnityEngine; public class CameraFollow : MonoBehaviour { public Transform target; // Reference to the character public float smoothSpeed = 0.125f; public Vector3 offset; public bool isPlaying; void Start() { isPlaying = true; offset =target.transform.position- transform.position; } void LateUpdate() { if (isPlaying) { if (target != null) { Vector3 targetPosition = new Vector3(transform.position.x, target.position.y, transform.position.z); transform.position = Vector3.Lerp(transform.position, targetPosition - new Vector3(0, offset.y, 0), smoothSpeed); } } } }