+-
我正在使用Unity 5.3.3f1 Personal,在我的代码中我必须使用Unity Ping类( http://docs.unity3d.com/ScriptReference/Ping.html).内部Unity Player( http://i.stack.imgur.com/0kHmN.jpg)中的构建和执行正常运行.但是当我尝试将此解决方案导出到WebGL时,我收到了下一个错误:
“error CS0246: The type or namespace name ‘Ping’ could not be found. Are you missing a using directive or an assembly reference?”
这是带有相关Ping代码的C#源代码:
using UnityEngine;
using System.Collections;
using System.Text;
using System.Collections.Generic;
using LitJson;
public class PingScript : MonoBehaviour
{
string Url = null, pingAddress = "192.168.0.180";
float pingStartTime;
// Use this for initialization
void Start()
{
CheckServerIp();
if (Url == null)
{
pingAddress = "192.168.1.210";
CheckServerIp();
}
print(Url);
}
// Update is called once per frame
void Update()
{
if (Url != null)
{
//Do something
}
}
void CheckServerIp()
{
bool internetPossiblyAvailable;
switch (Application.internetReachability)
{
case NetworkReachability.ReachableViaLocalAreaNetwork:
internetPossiblyAvailable = true;
break;
default:
internetPossiblyAvailable = false;
break;
}
if (!internetPossiblyAvailable)
{
Url = null;
}
Ping ping = new Ping(pingAddress);
pingStartTime = Time.time;
if (ping != null)
{
if (ping.isDone)
{
if (ping.time >= 0)
{
Url = "http://" + pingAddress + ":3200/api/pumpvalues";
}
}
}
}
}
最佳答案
Unity WebGL支持的唯一网络内容是 WWW和 UnityWebRequest类.您仍然可以使用WWW编写自己的ping函数,通过连接到服务器并检查连接是否成功来检查服务器是否可用.
点击查看更多相关文章
转载注明原文:c# – 将Unity解决方案导出到WebGL - 乐贴网