Can't disable MouseLook Y axis in pause screen

if(Input.GetKeyDown(onOffButton))
{
if (displayInventory)
{
displayInventory = false;

				firstPersonControllerCamera = gameObject.Find("First Person Controller").GetComponent("MouseLook");
	firstPersonControllerCamera.enabled = true;
mainCamera = gameObject.Find("Main Camera").GetComponent("MouseLook");
mainCamera.enabled = true;


		}
		else
		{
			
				firstPersonControllerCamera = gameObject.Find("First Person Controller").GetComponent("MouseLook");

	firstPersonControllerCamera.enabled = false; // X Axis
mainCamera = gameObject.Find("Main Camera").GetComponent("MouseLook");
mainCamera.enabled = false; // Y Axis
	

	
		}
	}

Currently When I open this inventory. I disabled the X axis so you cant look left or right.
To disable the Y axis I put

mainCamera = gameObject.Find("Main Camera").GetComponent("MouseLook");
mainCamera.enabled = false;

For some reason it gives me a error

NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value)
InventoryDisplay.Update () (at Assets/Inventory/Scripts/InventoryDisplay.js:94)

You either dont have gamobject named “Main Camera” in the scene at the time of call or it doesnt have MouseLook Component on it.

I dont think its a typo but use the generic version of GetComponent like:

...GetComponent<MouseLook>()

it ensures type safety.

So all in all, make a debug.Break() before this code and check if theres everything okay that i wrote. Also check for typos.
Or debug your variables to console:

Debug.Log(gameObject.Find("Main Camera"));
Debug.Log(gameObject.Find("Main Camera").GetComponent("MouseLook"));

And you will find out what is missing.