Camera deselecting dead players

Hello, so I got a problem where I have made an camera that zooms in and out when player 1-4 moves closer and further away from eachother. But my problem is that when I kill of for example Player1 i get an error that says “The object of type ‘Transform’ has been destroyed but you are still trying to access it”. I know how to kinda fix it, you have to remove it from the list of camera targets. I was just wondering how you did that easiest with code or just in general while playing the game.

In your Player component, or wherever you kill the player, you could get a reference to the script of the Camera which has that list of players, and access a new method like this one on your camera script:

public void RemovePlayer ( PlayerComponent player )
{
    listOfPlayers.Remove( player );
}