Hi Pramo,
Please copy/paste your code and apply code formatting, screenshots are bad enough but a photo of a screen is really hard to read for those that are offering to help you. Please consider our eyes
Regarding your issue, if your camera has a reliance on the position of the player, you need to consider what you want to do when the player dies. For example, are they going to respawn somewhere else? If so, rather than calling Destroy
you could just reduce the player lives and then move the player to the respawn position. The camera will then not have an issue with the object you are referencing it to being gone.
So, what do you want to happen when the player dies?
Updated Tue Oct 02 2018 14:02
Just another thought, if this is for the Red v Black game, you could consider having the camera as the player, but making the player’s avatar, e.g. the red sphere a child object of the camera. You’d put the player movement script on the camera, so it was directly changing the transform of the camera, the player’s avatar would effectively be dragged where the camera was moved, when the player’s avatar collides with something, you could then just destroy the child sphere, the camera would remain in place.
Note, you’d need a bit of an offset on the avatar, e.g. the distance between the sphere on the path and the camera above it.
This would also then allow for a respawn condition if the player has lives, you would then instantiate another player avatar (sphere) as a child of the camera and off you go again.
See also;
- Forum User Guides : How to apply code formatting within your post