Skip to content

Conversation

cesarchamorro
Copy link

This fix error message "Object reference not set to an instance of an object", it used to happen when player re spawn.
The problem is most likely that Camera.main is not initialized (this commonly happens).

This fix error message "Object reference not set to an instance of an object", it used to happen when player re spawn.
The problem is most likely that Camera.main is not initialized (this commonly happens).

// Update is called once per frame
void Update () {
Camera cam = Camera.main;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing so in every frame is not really a good way to do it. defining private camera inside the class and referencing Camera.main to it on Awake or on Start would be a nicer way to do . Also, the if statement is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants