var masterPing : Ping = new Ping("0.0.0.0");
function GetMasterServerPing()
{
masterPing = new Ping(MasterServer.ipAddress);
}
function OnGUI()
{
if(masterPing.isDone)
{
GUILayout.Label("Master Server Ping: " + masterPing.time " + ms");
} else {
GUILayout.Label("Master Server Ping unknown- still retrieving!");
}
}
If you are not yet connected to a server, or have not hosted a game, Network.Player will always return -1 because the ‘player’ is invalid! In the same way, even when you are connected, using Network.GetAveragePing on yourself will always return 0 (or close to 0) because there is no network lag between yourself and yourself! Otherwise, use Ping in the same way using NetworkPlayer.ipAddress instead of MasterServer.ipAddress, with whichever NetworkPlayer you are referring to.