我有一个 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;
//...
}
}
答案 0 :(得分:0)
将natCapable转换为UnityEngine.ConnectionTesterStatus
像这样:natCapable = Network.TestConnection() as ConnectionTesterStatus;