Problem exporting solution to WebGL
Good morning,
I'm using Unity 5.3.3f1 Personal and into my code I have to use the Unity Ping class ( http://docs.unity3d.com/ScriptReference/Ping.html ). The building and execution in internal Unity Player (attached image) runs properly. However when I try to export this solution to WebGL, I recieve the next error:
"error CS0246: The type or namespace name 'Ping' could not be found. Are you missing a using directive or an assembly reference?"
This is the C# source code with the related Ping code:
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";
}
}
}
}
}
Kind regards.
Answer by Chronovore · Apr 13, 2016 at 06:46 PM
According to the documentation, Unity's WebGL only supports WWW and UnityWebRequest classes.
The article also links to a free asset that enables some network functionality: https://www.assetstore.unity3d.com/en/#!/content/38367e