Unity Error were code is fine.

I am trying to make a small farming game similar to the old fashioned Farmville game that was on Facebook. I have made an array to create my land, however when I come to try and see if I can change the grass to a plowed field it doesn’t seem to work.

Visual studio claims there is nothing wrong but Unity says there is an Error with line 58. (Check screenshots) 8820193--1200592--image.png

Read this: How to fix a NullReferenceException error - Unity Forum
There is only 1 thing that can be null in that line. It’s Camera.main.

What else would it be? I am quite out of practice with coding so I am not sure what else can go there.

From the documentation:

Unity - Scripting API: Camera.main (unity3d.com)

Brilliant thank you! It’s working as intended now!

Just a clarification – Visual Studio is telling you that there are no compile-time problems. You don’t have any typos, invalid syntax, duplicate function names, etc. etc.

That doesn’t mean that you won’t have any run-time problems! Many kinds of errors happen because the language can’t 100% rule them out at compile-time.

In this case, Camera.main was null, and you can’t read the fields of a null object. C#, by default, doesn’t force you to check that an object is not null before using it, so the error can wind up happening at run-time.