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!

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: Unity - Scripting API: Ping )

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

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