Jump to content
  • Advertisement
Sign in to follow this  

Network.isServer and batchmode issue - level loading and GUI buttons

This topic is 2844 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm new too coding so would appreciate some help on this.

put simply when I run Unity i have to click the GUI button for it to run.

when i run Unity in batchmode, I believe it would run (play) but would still require the user input to initialize the server (if im correct that is).

So my guess is you would have to code it to...

if Network.isServer
Network.InitializeServer(32, connectPort, useNat);
if Network.isClient
Network.Connect(connectToIP, connectPort);

But where and how?

The code below is something else i tried which kind works but keeps disconnecting/reconnecting:

function OnGUI ()

if (Network.isServer == Network.isServer){
Network.InitializeServer(32, connectPort, useNat);
GUILayout.Label("SERVER connected");

} if (Network.peerType == NetworkPeerType.Disconnected){
//We are currently disconnected: Not a client or host
GUILayout.Label("SERVER disconnected");

//We've got a connection(s)!

Network.Connect(connectToIP, connectPort);

if (Network.peerType == NetworkPeerType.Connecting){

GUILayout.Label("Connection status: Connecting");

} else if (Network.peerType == NetworkPeerType.Client){

GUILayout.Label("Connection status: Client!");
GUILayout.Label("Ping to server: "+Network.GetAveragePing( Network.connections[0] ) );

} else if (Network.peerType == NetworkPeerType.Server){

GUILayout.Label("Connection status: Server!");
GUILayout.Label("Connections: "+Network.connections.length);
GUILayout.Label("Ping to first player: "+Network.GetAveragePing( Network.connections[0] ) );

if (GUILayout.Button ("Disconnect"))


Another thing i tried was a application start method but the server and client loaded 1 instead of 0.

All I want is the server to run in a headless mode. I don't have the pro version, I don't think this is whats stopping me though.

For debugging I ran without the batchmode command just to see.

Just so you know what it is I'm trying to do;

I set up 4 scenes, one is mainly for the server and the rest for the player.
The server is running - scene 0

a player loads up his web player "scene[1]" and clicks continue (eventually I get stats and spawn position passed into the game)

this loads the correct level "scene[2]" ( and their last spawn position)

player dies and presented with scene[3] (You died...(spawn saved))
count down to load

Load scene[1] / end of loop

This is where I ran into problems, it was like the clients browser did not know the server was running
I've been putting bits and pieces and trying things out for days now, my head will explode soon...please any help in any way :(

even a brief moment of clarity would stop this head ache

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!