Created
August 25, 2023 05:57
-
-
Save Venkat-Swaraj/781a4aa55056c6136fec448152fb715f to your computer and use it in GitHub Desktop.
To find IP address of a player in unity.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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