Starting Host and Client within the same OnClick method.

Hello everyone,

I am trying to start the server and client within the same method that will be assigned to a button. Basically when a player loads in the scene and clicks the button, the StartHost method in the networkManager.Singleton will run if any other host has been initialized before. When the player in other session will then clicks the button the StartClient will run since the host has already been started. Could not figure out the way to achieve this behaouviour. So the same method needs to check if the host has been started if not starts the host and starts the client if host has already been started.

Aprreciate for the help. thank you.

You cannot automatically detect or decide for the user whether the game should start as host or client.The player actively needs to make that decision.

Note: there is one exception which is LAN games. You can announce a host to other machines and actively scan for that but it only works in a LAN within the same subnet eg 192.168.. so this has very limited applicability and the amount of work to put into this is in no relation to just providing two buttons „start host“ and „join game“.

1 Like

Thank you, I have been trying this a lot. I will then procede with two buttons as you suggested.