ipueyo
ipueyo

Reputation: 51

Export Unity solution to WebGL

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 (https://i.sstatic.net/0kHmN.jpg) 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";
                 }
             }
         }
     }
 }

Upvotes: 4

Views: 1034

Answers (1)

Programmer
Programmer

Reputation: 125245

The only Network stuff supported in Unity WebGL are the WWW and the UnityWebRequest class. You can still write your own ping function with WWW that checks if the server is available by connecting to it and checking if connection was successful.

Upvotes: 4

Related Questions