I shamelessly copied this basic networking code from the manual and I do seem to get a connection going.
public class WNetriumNetwork : NetworkBehaviour {
public NetworkManager manager;
public NetworkClient client;
public short playerNum;
public bool startup = true;
void Update () {
if (startup) {
if (Input.GetKeyDown (KeyCode.S)) {
startup = false;
StartServerAndLocal ();
}
else if (Input.GetKeyDown (KeyCode.C)) {
startup = false;
Connect ();
}
}
}
public void StartServer () {
NetworkServer.Listen (manager.networkPort);
}
public void StartServerAndLocal () {
StartServer ();
StartLocalClient ();
}
public void StartLocalClient ()
{
client = ClientScene.ConnectLocalServer ();
client.RegisterHandler (MsgType.Connect, OnConnected);
}
public void Connect ()
{
client = new NetworkClient ();
client.RegisterHandler (MsgType.Connect, OnConnected);
client.Connect (manager.networkAddress, manager.networkPort);
}
public void OnConnected (NetworkMessage message) {
WGame.game.RiderInitNetworked (null, null, this);
}
}
RiderInitNetworked (), meanwhile, calls this:
public class WGame : MonoBehaviour {
public void RiderInitNetworked () {
//[...]
sys.rider = Instantiate (rider, startPoint.transform.position, startPoint.transform.rotation);
NetworkServer.Spawn (sys.rider.gameObject);
}
}
}
…and nothing’s spawned server-side. What’s more, I have a server-side GameObject which doesn’t get re-enabled on play, which has me wonder if this isn’t something to do with client readiness. In addition, I have online and offline scenes set up in the inspector but no scene change.