【问题标题】:Variable defines as variable of the System.Object type变量定义为 System.Object 类型的变量
【发布时间】:2014-08-24 06:41:54
【问题描述】:

我有一个 ConnectionTesterStatus 类型的变量。当我在 switch 块中比较它时,我收到一个错误:

运算符“==”不能与“UnityEngine.ConnectionTesterStatus”类型的左侧和“System.Object”类型的右侧一起使用。

private var natCapable : ConnectionTesterStatus = ConnectionTesterStatus.Undetermined;

function TestConnection()
{
    // Start/Poll the connection test, report the results in a
    // label and react to the results accordingly    
    natCapable = Network.TestConnection();
    switch(natCapable) // Error
    {
        case ConnectionTesterStatus.Error:
            //...
            break;
        //...
    }
}

【问题讨论】:

  • 我对 Unityscript 了解不多,但第一行的变量声明看起来很奇怪。尝试将其替换为 Network scripting api 参考中的声明。还要检查 TestConnection 的返回类型。

标签: networking unity3d unityscript


【解决方案1】:

将 natCapable 转换为 UnityEngine.ConnectionTesterStatus

像这样:

natCapable = Network.TestConnection() as ConnectionTesterStatus;

【讨论】:

  • 在这种情况下我得到一个错误:';'预期的。在末尾插入分号
  • 对不起,那是 C#,更新到 UnityScript(我希望精通 UnityScript 的人可以查看演员表)
  • 不幸的是,它说“UnityEngine.ConnectionTesterStatus”是一种值类型。 'as' 运算符只能用于引用类型。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-14
  • 1970-01-01
  • 2015-11-15
  • 2016-02-01
相关资源
最近更新 更多