GetComponent() -> NullRefereceException ??

Hallo

My script(ReadShield.js) is in the screenshot below:

the highlighted line marks the critical location: Sometimes(not always) I get this error:
NullReferenceException
UnityEngine.Component.GetComponent (System.String type)
ReadShield.OnTriggerEnter (UnityEngine.Collider other) (at Assets\Scripts\ReadShield.js:11)

It seems that unity does not always find the specified component or the “current” camera.

Please help me, I’m getting mad because of that.

385319--13276--$unbenannt_146.png

You may want Camera.main instead of Camera.current.

Thank you, that helped me much! But what is the difference? Why does Camera.main work better than Camera.current?

camera.main = the camera with the MainCamera tag

camera.current = the camera that was rendering at that time (if you have 2 or are in the editor this makes a difference)