Object reference not set to an instance of an object

I’m trying to make a script that lets me switch from one camera to another but I keep getting the same error

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Switch : MonoBehaviour {

    GameObject Camera1;
    GameObject Camera2;

	// Update is called once per frame
	void Update () {
        if (Input.GetKeyDown("1"))
        {
            Camera1.SetActive(true);
            Camera2.SetActive(false);
        }
        if (Input.GetKeyDown("2"))
        {
            Camera1.SetActive(false);
            Camera2.SetActive(true);
        }
    }
}

Your Camera1 and Camera2 fields both need to be assigned gameobjects in the inspector, on every object that has your Switch component.

If they’re assigned properly, then find the line and script reference in your error message, and that will tell you which script is causing the error and which line in that script is the problem. This error message occurs when you’re trying to do something to a variable that doesn’t have anything assigned to it.