Skip to content

Instantly share code, notes, and snippets.

@Venkat-Swaraj
Created August 25, 2023 05:57
Show Gist options
  • Save Venkat-Swaraj/781a4aa55056c6136fec448152fb715f to your computer and use it in GitHub Desktop.
Save Venkat-Swaraj/781a4aa55056c6136fec448152fb715f to your computer and use it in GitHub Desktop.
To find IP address of a player in unity.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class findIPaddress : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
StartCoroutine(getIPRequest("https://api.ipify.org?format=json"));
}
private IEnumerator getIPRequest(string uri)
{
UnityWebRequest uwr = UnityWebRequest.Get(uri);
yield return uwr.SendWebRequest();
if (uwr.isNetworkError || www.isHttpError)
{
Debug.Log("Error While Sending: " + uwr.error);
}
else
{
Debug.Log("Received: " + uwr.downloadHandler.text);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment