An error occurs Object reference not set to an instance of an object

Situation description:

I mounted a script on the initial Main Camera of Unity's Hierarchy. Later, for other reasons, I deleted the original Main Camera, then created a new Camera, named it Main Camera, and mounted the same script as before. After that, it was found that the following bug would appear: Object reference not set to an instance of an object.

reason:

The object is not referenced to an instance of the object. That is, an object is not instantiated. When a variable is declared, but it is not assigned a value, and it is still null, an error will be reported when it is used.

Solution:

Click to select the new Camera, and in the Inspector property settings, find the Main Camera in the tag drop-down menu and select it. Re-run the program, and the error will be eliminated!

 

 

Guess you like

Origin blog.csdn.net/qq_44983147/article/details/124346835