Hello! I’m trying to make a main menu where you can open an options one, quit the game and start it. Before assigning any tasks to any buttons, I first had to write the general script. I was following a tutorial and copied exactly what the guy wrote:
using UnityEngine;
using UnityEngine.SceneManagement;
public class MainMenu : MonoBehaviour,
{
public GameObject OptionsMenu;
public GameObject MainMenu;
}
public void OpenOptionsPanel()
{
OptionsMenu.SetActive(true);
}
public void CloseOptionsPanel()
{
OptionsMenu.SetActive(false);
}
public void QuitGame()
{
Application.Quit();
}
public void PlayGame()
{
SceneManager.LoadScene("Intro");
}
The errors that show up are the following (in order):
- Assets/Script/MainMenu.cs(4,39): error CS1031: Type expected.
- Assets/Scripts/Mainmenu.cs(10,1): error CS8803: Top-level statements must precede namespace and type declarations.
- Assets/Scripts/MainMenu.cs(10,1): error CS0106: The modifier “public” is not valid for this item. This last one also shows up in lines 15,1; 20,1; and 25,1.
I think one of the main problems is that it should be “public void” and not “public class” at the beggining of it all, but I left it like that because I’m not really sure about it. I’m completely new to coding and programming, so if any of these mistakes seem silly please bear with me. I’ll appreciate any input you guys can give me.