Search Unity

Auto reconnect for client

Discussion in 'Scripting' started by McC1oud, Dec 12, 2018.

  1. McC1oud

    McC1oud

    Joined:
    Mar 14, 2015
    Posts:
    96
    I am attempting to create an auto re-connection for clients that drop out. My idea is to have a looping check on my network manager script that looks in the scene and is unable to find the player object spawned in my the server. If it can't find this object, recconnect again with StarClient.

    I'm falling into quite a few bugs with this. Is there just a trigger function for the client to reconnect automatically when it detects itself disconnected from the server?

    Code (CSharp):
    1. if (!GameObject.Find("JO(Server)"))
    2.             {
    3.                 StartCoroutine("RecconectTime");
    4.             }
    5.  
    6. IEnumerator RecconectTime()
    7.     {
    8.         yield return new WaitForSeconds(5);
    9.  
    10.         NetworkManager.singleton.networkAddress = "localhost";
    11.  
    12.         NetworkManager.singleton.StartClient();
    13.  
    14.         yield return new WaitForSeconds(5);
    15.  
    16.     }