So I am writing a menu for my game and I am having the following issue where the Console spams a “object not set to an instance of an object” message every time i click on the “Start Game” option. Here is what I have for my game:
public class MainMenuManager : MonoBehaviour {
public enum MenuState { MainDisplay, StartGame, Options, Extras, Exit}
public MenuState CurrentMenuState = MenuState.MainDisplay;
MainMenu_StartGame obj_StartGame;
void Awake()
{
obj_StartGame = GameObject.FindGameObjectWithTag("MainMenuItems").GetComponent<MainMenu_StartGame>();
}
public void OnStartGame()
{
CurrentMenuState = MenuState.StartGame;
}
void Update()
{
switch (CurrentMenuState)
{
case MenuState.StartGame:
obj_StartGame.ShowContent(); //NOTE: This is where I am getting the error
break;
}
}
}
public class MainMenu_StartGame : MainMenuManager
{
protected enum StartGameState { StoryMode, Trials, Return}
protected enum StoryModeState { NewGame, LoadGame, Return}
public MainMenu_StartGame(){
}
// Use this for initialization
public void ShowContent () {Debug.Log ("Start Game");}
}
Can anyone find what I am doing wrong? I Many thanks in advance!