Network.Connect() in code without button pressed

Is there a way to use Network.Connect() in code but without button attached to it ?

if(GUILayout.Button("Join"))
{
  Network.Connect(IP,25001);
}

I want to load a scene and on load connect automatically to a server but i dont want the player to press connect button in the scene in order to connect. Using Network.Connect() in code doesnt seem to work individualy is there another way?

Network.Connect is in no way dependent on OnGUI. You just need to have a server already running and know its IP. If you can't connect, there's something wrong with the server or your computer's network settings.

1 Answer

1

just place it in the Start()

Start()
{
    Network.Connect(IP,25001);
}

it will connect it once at the start