我正在使用Unity 5.3.3f1 Personal,并且在我的代码中需要使用Unity Ping类(http://docs.unity3d.com/ScriptReference/Ping.html)。在内部Unity播放器 (http://i.stack.imgur.com/0kHmN.jpg) 中构建和执行可以正常运行。但是,当我尝试将此解决方案导出到WebGL时,我会收到以下错误:
"error CS0246:找不到类型或命名空间名称'Ping'。您是否缺少using指令或程序集引用?"
这是相关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";
}
}
}
}
}