Here I am creating a multiplayer game with Unity Networking. What I want is to start the game when both Server and client is connected. In my game I have 2 players one will act as a server who hosts the game and the other acts as a client who connects to that host with the servers IPAddress. So when both are connected and ready to play i want to start the game. Can anyone help me how can i get to know that both are connected.
Here is the code what I am using.
public NetworkManager manager;
public void startServerr()
{
NetworkServer.Listen(9000);
NetworkServer.RegisterHandler(MsgType.Connect, OnConnected);
NetworkServer.RegisterHandler(MsgType.Disconnect, OnDisconnected);
NetworkServer.RegisterHandler(MsgType.Error, OnError);
manager.StartHost();
}
public void connectToServer()
{
manager.networkAddress = PlayerPrefs.GetString("oppPlayerIP");
manager.StartClient();
}
public void OnConnected(NetworkMessage netMsg)
{
Debug.Log("Client Connected");
}
public void OnDisconnected(NetworkMessage netMsg)
{
Debug.Log("Disconnected");
}
public void OnError(NetworkMessage netMsg)
{
Debug.Log("Error while connecting");
}