I’ve Coded a Main menu for my game, but when i click “Start Game” is closes the main menu and does load the the map or anything? this is my script
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Singleplayer : MonoBehaviour
{
public Singleplayer instance;
public string CurrentMenu;
public List<MapSetting> MapList = new List<MapSetting>();
public MapSetting CurrentMap = null;
public int oldprefix;
public bool IsMatchStarted = false;
void Start()
{
instance = this;
CurrentMenu = "Main";
CurrentMap = MapList[0];
}
void FixedUpdate()
{
instance = this;
}
void OnGUI()
{
if (CurrentMenu == "Main")
Menu_MainMenu();
if (CurrentMenu == "Singleplayer")
Menu_Singleplayer();
if (CurrentMenu == "SelectMap")
Menu_SelectMap();
if (CurrentMenu == "StartGame")
Menu_StartGame();
}
public void NavigateTo(string nextmenu)
{
CurrentMenu = nextmenu;
}
private void Menu_MainMenu()
{
if(GUI.Button(new Rect(10, 10, 200, 50), "Singleplayer"))
{
NavigateTo("Singleplayer");
}
GUI.Button(new Rect(220, 10, 200, 50), "Multiplayer");
}
private void Menu_Singleplayer()
{
//Back to Main Menu Button
if(GUI.Button(new Rect(430, 10, 200, 50), "Back"))
{
NavigateTo("Main");
}
//Choose Map Button
if(GUI.Button(new Rect(220, 10, 200, 50), "Select Map"))
{
NavigateTo("SelectMap");
}
if (GUI.Button(new Rect(10, 10, 200, 50), "Start Game"))
{
NavigateTo("StartGame");
}
GUI.Box(new Rect(220, 70, 200, 25), CurrentMap.MapName); // Change (CurrentMap.MapName) Too (CurrentMap.MapLoadName) To Change the Selected Map Name To Load Screen name
}
private void Menu_StartGame()
{
if (Network.isServer)
{
//Start Game Button
if (GUI.Button(new Rect(10, 10, 200, 50), "Start Game"))
{
networkView.RPC("Client_LoadSinglePlayerMap", RPCMode.All, CurrentMap.MapLoadName, oldprefix + 1);
oldprefix += 1;
IsMatchStarted = true;
}
}
}
private void Menu_SelectMap()
{
if(GUI.Button(new Rect(10, 10, 200, 50), "Back"))
{
NavigateTo("Singleplayer");
}
GUILayout.BeginArea(new Rect(220, 10, 150, Screen.height));
foreach(MapSetting map in MapList)
{
if(GUILayout.Button(map.MapLoadName))
{
NavigateTo("Singleplayer");
CurrentMap = map;
}
}
GUILayout.EndArea();
}
[System.Serializable]
public class MapSetting
{
public string MapName;
public string MapLoadName;
public Texture MapLoadTexture;
}
[RPC]
void Client_GetSingleplayerMatchSettings(string map, string mode, string others)
{
CurrentMap = GetMap(map);
}
public MapSetting GetMap(string name)
{
MapSetting get = null;
foreach(MapSetting st in MapList)
{
if(st.MapName == name)
{
get = st;
break;
}
}
return get;
}
[RPC]
void Client_LoadSinglePlayerMap(string map, int prefix)
{
Network.SetLevelPrefix(prefix);
Application.LoadLevel(map);
}
}