NullReferenceException on ThirdPersonControlller

Hello. I have added a Third Person Controller on my character, and I did not edit the script.

Then I got a NullReferenceException, and it seemed to be on line 129.

Edited code on line 129:

var cameraTransform = Camera.mainCamera.transform;

Code on line 129 before edited:

var cameraTransform = Camera.main.transform;

I edited it to see if it would change if it was a problem with the main camera. However it kept giving me a NullReferenceException.

Do any of you coders have a solution to this?

If so, please answer!

Thanks!

No it got deleted. I made another one and called it Main Camera. with the space in between.

yeah but it needs the MainCamera tag

How do I add that?

I cannot believe you asked a whole separate question just to ask "How do I add a tag" : http://answers.unity3d.com/questions/441349/how-to-give-camera-the-maincamera-tag.html Have you heard of google ? : http://www.lmgtfy.com/?q=unity+tag

1 Answer

1

Do you have a camera in your scene with the MainCamera tag? Camera.main will return null if you don’t, or if it is disabled