basic question on onClick for panels

I have some buttons on panels that I’m using as a menu. I have a panel called mainMenu with a button called fightButton and On Click for fightButton set to mainMenu.menuChange with the string fightMenu. I have another panel called fightMenu.

I’m expecting “fightMenu” to be passed into string menuName, find the gameobject called fightMenu (panel). Then set the first panel not active and the menu fightMenu as the active. When I click the fightButton I get Object reference not set to an instance of an object on line 13 which is the (if mainMenuButton.name == “fightMenu”) line. If it didn’t find the object why wouldn’t it give an error on the previous line?

using UnityEngine;
using UnityEngine.UI;

public class mainMenu : MonoBehaviour {

    public GameObject mainMenuPanel;
    GameObject mainMenuButton;

    public void menuChange(string menuName) {

        mainMenuButton = GameObject.Find (menuName);

        if (mainMenuButton.name == "fightMenu") {
            print ("fight button pressed");
            mainMenuPanel.SetActive(false);

        }
    }
}

Find returns null if the object is not found. Thus the error later.

This all seems like there is some deeper code structure issues here. Find is generally to be avoided. And there are often better solutions then checking a GamObjects name.