Camera change targets when new object appears or Camera change targets by pressing a button

The game I am making has a third person camera.

My idea is for the camera to switch targets when a new game object is instantiated into the game when a key is pressed.

So the original target is the player and the camera will move change targets once the new game object shows up. Then when the game object disappears from the scene the camera will change back to the Player. ,I have a third person controlled character and a third person camera. I wanted the camera to swap targets from the original player to the new one. This will happen at the push of a key.

So the character gets instantiated into the scene and the camera will move to the newly created character. If the button is pressed again. It will spawn another object and move to that target and so on. If the objects disappear the camera will return back to the original Player game object. Any help would be appreciated.

Good day.

There are free assets in assets store with cameras with a “follow” function. You should use that or at least use part of its code.

ITs really a simple code, but if you want a good camera movement, you need to do it smooth and carefull.

Bye!