S
S
Senture2018-04-10 21:03:20
Computer networks
Senture, 2018-04-10 21:03:20

How to wait to connect to the server in multiplayer on Unity?

Hello! There is a code:

private NetworkManager manager;

    [SerializeField] private GameObject netManager;

  void Start ()
    {
        Debug.Log("Connection...");
        manager = netManager.GetComponent<NetworkManager>();
        manager.StartClient();
        // Как сделать вот тут задержку и не писать в логе "Connection" пока сервер не будет подключен
        Debug.Log("Connection");
    }

It is necessary to make it so that after the line manager.StartClient(); the code was not executed further until a connection with the server was established, and if the connection fails, output something like "Connection failed" to the log. Otherwise, if the delay is not made, the user can work with UI elements on the stage, otherwise it is not necessary, you need to allow the elements to be used after the connection is established.
Hope I explained it clearly, if you have any questions feel free to ask.
PS Thank you all!!!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Basmanov, 2018-04-10
@Senture

You can, for example, inherit from NetworkManager and overload the OnStartClient method , and then fire an event inside or something else.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question