4
我正在使用Unity 5.3.3f1個人和我的代碼我必須使用統一Ping類(http://docs.unity3d.com/ScriptReference/Ping.html)。 Unity Player內部的構建和執行(http://i.stack.imgur.com/0kHmN.jpg)運行正常。然而,當我嘗試導出這個解決方案的WebGL,我收到了一個錯誤:導出到WebGL的統一解決方案
"error CS0246: The type or namespace name 'Ping' could not be found. Are you missing a using directive or an assembly reference?"
這是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";
}
}
}
}
}
WebGL有很多限制和奇怪的錯誤。您可以使用JavaScript編寫相同的代碼,並從Unity遠程調用它。這肯定會起作用。 [爲Unity編寫瀏覽器插件的文檔](http://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html) –