Question by 
               tpwolf602 · Oct 07, 2018 at 01:17 AM · 
                networkingbuttonscene  
              
 
              Scenes changing problem!
I followed the tutorial on Youtube to setup a menu and the disconnect button in Game scene, and found out that the code not work properly (due to OnLevelWasLoaded ) . How to correct the code and make the disconnect button in another game scene work?
 public void StartupHost()
 {
     SetPort();
     NetworkManager.singleton.StartHost();
 }
 public void JoinGame()
 {
     SetIPAddress();
     SetPort();
     NetworkManager.singleton.StartClient();
 }
 void SetIPAddress()
 {
     string ipAdress = GameObject.Find("InputFieldIPAddress").transform.Find("Text").GetComponent<Text>().text;
     NetworkManager.singleton.networkAddress = ipAdress;
 }
 void SetPort()
 {
     NetworkManager.singleton.networkPort = 7777;
 }
 void OnLevelWasLoaded(int level)
 {
     if (level == 0)
     {
         SetupMenuButtons();
     }
     else
     {
         SetupOtherSceneButtons();
     }
 }
 void SetupMenuButtons()
 {
     GameObject.Find("ButtonStartHost").GetComponent<Button>().onClick.RemoveAllListeners();
     GameObject.Find("ButtonStartHost").GetComponent<Button>().onClick.AddListener(StartupHost);
     GameObject.Find("ButtonJoinGame").GetComponent<Button>().onClick.RemoveAllListeners();
     GameObject.Find("ButtonJoinGame").GetComponent<Button>().onClick.AddListener(JoinGame);
 }
 void SetupOtherSceneButtons()
 {
     GameObject.Find("ButtonDisconnect").GetComponent<Button>().onClick.RemoveAllListeners();
     GameObject.Find("ButtonDisconnect").GetComponent<Button>().onClick.AddListener(NetworkManager.singleton.StopHost);
 }
 
edit: I 've tried adding public void StopGame() { SceneManager.LoadScene(0); } to disconnectButton in Game scene , but all buttons overlapped as the scene went back to Menu.
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Button to change a scene 1 Answer
How to implement voice overs linked with buttons? 0 Answers
Scene doesn't work 1 Answer
setactive panel from other scene 0 Answers
How To pass from level to the next after winning, with one button ? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                