| 在搜寻了百度许久,也打包测试了好几版之后,终于在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();
    }
}
 |