Unity 5.3.3f1 Personal kullanıyorum ve koduma Unity Ping sınıfını kullanmam gerekiyor (http://docs.unity3d.com/ScriptReference/Ping.html). Dahili Birlik Oynatıcıdaki (http://i.stack.imgur.com/0kHmN.jpg) bina ve yürütme düzgün şekilde çalışıyor.İhracat Birliği çözümü WebGL'ye
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'de bir çok sınırlama ve garip hata var. Aynı kodu javascript’e yazabilir ve Unity’ten uzaktan yazabilirsiniz. Bu kesinlikle işe yarayacak. [Unity için tarayıcı eklentileri yazmadaki dokümanlar] (http://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html) –