How do I set my instantiated object to main camera

How do I set my instantiated object to main camera after the main player gets destroyed?

Code:

public class camerafollow : MonoBehaviour
{

public Transform target;
public Vector3 offset;
[Range(1, 10)]
public float smoothFactor;

// Start is called before the first frame update
private void FixedUpdate()
{
    Follow();
}

// Update is called once per frame
void Follow()
{
    Vector3 targetPosition = target.position + offset;
    Vector3 smoothPosition = Vector3.Lerp(transform.position, targetPosition, smoothFactor * Time.fixedDeltaTime);
    transform.position = smoothPosition;
}

}

// Make target static:


public static Transform target;


// When you need to instantiate your new player (or object), set it’s transform to the new target.


var newTarget = Instantiate(newTargetObject);

cameraFollow.target = newTarget.transform;


// Just remember to set your target in the beginning to avoid a null reference exception.