在搜尋了百度許久,也打包測驗了好幾版之后,終于在Unity官方論壇找到了解答,原地址:https://answers.unity.com/questions/1731994/get-the-device-ip-address-from-unity.html
直接上代碼
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using UnityEngine;
using UnityEngine.UI;
public class TestLocationService : MonoBehaviour
{
public Text txt;
private void Start()
{
txt.text = GetLocalIPv4();
}
public string GetLocalIPv4()
{
return Dns.GetHostEntry(Dns.GetHostName())
.AddressList.First(
f => f.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
.ToString();
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/292072.html
標籤:其他
上一篇:Glide原始碼學習-三大快取
