gpt4 book ai didi

c# - 将 Unity 解决方案导出到 WebGL

转载 作者:太空狗 更新时间:2023-10-30 01:16:07 27 4
gpt4 key购买 nike

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

"error CS0246: The type or namespace name 'Ping' could not be found. Are you missing a using directive or an assembly reference?"

这是带有相关 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";
}
}
}
}
}

最佳答案

Unity WebGL 支持的唯一 网络内容是 WWWUnityWebRequest类(class)。您仍然可以使用 WWW 编写自己的 ping 函数,通过连接到服务器并检查连接是否成功来检查服务器是否可用。

关于c# - 将 Unity 解决方案导出到 WebGL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36542842/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com