变量定义为System.Object类型的变量

时间:2014-08-24 06:41:55

标签: networking unity3d unityscript

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

运算符'=='不能与'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;
        //...
    }
}

1 个答案:

答案 0 :(得分:0)

将natCapable转换为UnityEngine.ConnectionTesterStatus

像这样:

natCapable = Network.TestConnection() as ConnectionTesterStatus;