How to Make Camera stop following Player when player died in the last position

i want to make my camera stop following player when the player died but in the last player position, i’ve tried different code but still not working,here’s the code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraFollow : MonoBehaviour
{
    public float FollowSpeed = 2f;
    public float yOffset = 1f;
    public Transform target;
    public PlayerStat stat;

    void Update()
    {
        cameraFollow();
        cameraDead();
    }

    private void cameraFollow()
    {
        Vector3 newPos = new Vector3(target.position.x, target.position.y + yOffset, -10f);
        transform.position = Vector3.Slerp(transform.position, newPos, FollowSpeed * Time.deltaTime);
    }

    private void cameraDead()
    {
        if (stat.isDead)
        {

            //code
        }
    }
}
    void Update()
    {
        if (!stat.isDead) // player not dead?
        {
            Vector3 newPos = new Vector3(target.position.x, target.position.y + yOffset, -10f);
            transform.position = Vector3.Slerp(transform.position, newPos, FollowSpeed * Time.deltaTime); 
        }
    }

Another approach is to have your GameManager script disable the CameraFollow script when the player dies.

its works, i try to disable the camera follow script and its works perfectly. Thank You

Please don’t use the 2D-Physics tag unless you’re asking about physics. These tags are used to answer questions on those subjects.

I’ll go ahead and remove it.

Thanks.

Hi, in these cases, I use another Virtual Cam driven by Cinemachine, so you have total control of what to display, you can just increase the Priority of this second cam through an event