- Home /
How to leave / Exit the LobbyManager and go back to main menu ?
Hi, I think my question is clear in its title but I can tell a bit more :
I have a scene with a Network Lobby Manager for a 2 players versus game.
When 2 players join, the game start on a new scene.
When a player wins/loses, a scene shows the result of the game
Then it goes back to Lobby (I did not find anyway to start another game without going back to Lobby)
There I'm stuck : what to do to leave the LobbyManager scene and go back to a main menu (for Solo playing for example) ? I did find this to go back to lobby after Game Over :
SendReturnToLobby();
Does exist a function like say CloseLobbyManager() or ExitLobbyManagerToScene (scene) ?...
Thank You for your help.
I'm not sure i understand this. So are you just trying to leave the lobby manager and go back to the main menu?
Exact, for the player to go back to main menu and either play solo $$anonymous$$ode, or go again in versus mode, or anywhere else (credits, settings...).
Answer by PiFLYON · Dec 01, 2016 at 10:13 AM
It's ok, I found a way... It's "Network.Disconnect()".
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class VersusExitButton : MonoBehaviour {
private GameObject LBM;
void Start() {
LBM = GameObject.Find ("LobbyManager");
}
void OnMouseDown () {
Network.Disconnect ();
Destroy (LBM);
GameManager.gameManager.MainLoadScene ("scene00"); // SCENE SUIVANTE
}
}
If i leave the lobby like this and go back to the lobby, the lobby seems broken and does not behave normal,
Hi wickedFreak,
Here is the code I finally made to achieve what I wanted. I'm not sure it is the correct way (I was expecting an answer from Unity community which did not came as you can see).
Hope this will help. (In the comments "attends un peu" means "wait for a little while", it's for letting time to get things done before exiting). Put this code on any visible GameObject.
public class VersusExitButton : $$anonymous$$onoBehaviour {
void Start() {
}
void On$$anonymous$$ouseUp () {
Network$$anonymous$$anager.singleton.StopClient ();
Network$$anonymous$$anager.singleton.StopHost ();
NetworkLobby$$anonymous$$anager.singleton.StopClient ();
NetworkLobby$$anonymous$$anager.singleton.StopServer ();
NetworkServer.DisconnectAll ();
//Network.Disconnect ();
StartCoroutine (ExitDelay());
}
IEnumerator ExitDelay() {
yield return new WaitForSeconds (0.1f);//attends un peu
Destroy(NetworkLobby$$anonymous$$anager.singleton.gameObject);
yield return new WaitForSeconds (0.1f);//attends un peu
Game$$anonymous$$anager.game$$anonymous$$anager.$$anonymous$$ainLoadScene ("scene00"); // SCENE SUIVANTE
}
}
Answer by Dplepler · Aug 24, 2020 at 04:04 PM
I know this is a bit late but I am a newbie and I am still stuck on this error. I tried Pifloyn's answer but I don't know what the GameManager is and it seems to bring me to the lobby scene but my mouse disappears.. Does anyone know how to fix this? Thanks