Unassigned Reference Exception, Variable not Assigned – Unity3D

The syntax error this time is : “UnassignedReferenceException : The variable XYZ of ABC.csharp has not been assigned”

This error says that you have declared a variable and used is as a GameObject, but no GameObject in the Scene has been assigned to the variable.

public GameObject camera;
 void Start () {
 camera.gameObject.SetActive(true);
 }

Therefore, you have to assign the variable camera, for example, to an object which is tagged in the Inspector. Let us say that the Object Main Camera in the Hierarchy is labelled as MainCamera in the Tag field, to assign the variable camera to the Object Main Camera, the code should be written as follow :-

public GameObject camera;
 void Start () {
 camera = GameObject.FindGameObjectWithTag("MainCamera");
 camera.gameObject.SetActive(true);
 }