Unity2021.3.35f1,运行模式为ENGINE_SERVER
1.环境设置
Windows设置
安卓设置
2.代码修改
ConnectionProperties中的server必须与真实IP一样,所以需要新增一个获取IP的函数
public string GetLocalIPAddress()
{
IPHostEntry host;
string localIP = "0.0.0.0";
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
localIP = ip.ToString();
}
}
return localIP;
}