我正在使用 Unity 5.3.3f1 Personal 并且在我的代码中我必须使用 Unity Ping 类(http://docs.unity3d.com/ScriptReference/Ping.html)。内部 Unity Player ( http://i.stack.imgur.com/0kHmN.jpg ) 中的构建和执行运行正常。但是,当我尝试将此解决方案导出到 WebGL 时,我收到下一个错误:
“错误 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";
}
}
}
}
}