Now, before we try and do anything with the go variable, we check to see that it is not null. If it it null, then we display a message.
Try/Catch Blocks
Another cause for NullReferenceException is to use a variable that should be initialised in the Inspector. If you forget to do this, then the variable will be null. A different way to deal with NullReferenceException is to use try/catch block. For example, this code: