- Home /
How to find out a players ping?
Hey! Does anyone know how I can find a players ping. All the answers that I have found so far have been outdated, so some updated info would be great. Thanks!
Have you tried using the Ping class?
Answer by ChrisKurhan · Dec 16, 2016 at 06:38 PM
In my experience, the Ping class feels clunky to use if you just want to show the user's ping. You have to do something like
Ping ping = new Ping("ipaddress")
while(!ping.isDone)
{
yield;
}
return ping.time;
within some yield-able method. (ping reference: https://docs.unity3d.com/ScriptReference/Ping.html )
While this works, I don't like it.
Assuming you are using UNET, there's a oneliner you can do:
NetworkManager.singleton.client.GetRTT();
Which I feel is much cleaner and easier to do. NetworkClient reference: https://docs.unity3d.com/ScriptReference/Networking.NetworkClient.html
Answer by mahecharpi · Feb 27, 2018 at 05:43 PM
void OnGUI() { if (NetworkClient.allClients.Count!=0) { int ping = NetworkClient.allClients[0].GetRTT(); textPing.text = ping == 0 ?"Host":ping + " ms"; } }
it gives the ping with the host player
Your answer
Follow this Question
Related Questions
Networking: Cannot get average ping to server 0 Answers
Ping a Matchmaking room 1 Answer
Ping an Ip 1 Answer
Unity networking tutorial? 6 Answers
Very Low FPS 1 Answer