【发布时间】:2015-06-25 17:34:37
【问题描述】:
备份我之前回答的问题 (Displaying variables using gui in Unity),我需要一些帮助来解决更多问题!我收到一个错误提示
无法将类型 string 隐式转换为 bool。
这是我使用的(改编的)代码:
using UnityEngine;
using System.Collections;
public class ConnectGUI : MonoBehaviour {
//Variables
string Map;
string Gamemode;
//Var set
void Start () {
Map = "No map selected!";
Gamemode = "No game mode selected!";
}
//Configurable settings.
void OnGUI () {
//Map GUI
GUI.Box(new Rect(10,10,200,90), "Map selected: "+ Map);
if(GUI.Button (new Rect(10,50,90,20), "Pier")){
Map = "Pier";
}
//Game mode GUI
GUI.Box (new Rect(350,10,250,90), "Mode selected: "+ Gamemode);
if(GUI.Button (new Rect (375,50,125,20), "Team Deathmatch")){
Gamemode = "Team Deathmatch";
}
}
//ConnectToServer
void Connect () {
if (Map = "Pier"){
if (Gamemode = "Team Deathmatch") {
Application.LoadLevel("Pier TeamDM");
}
}
}
}
有解决这个错误的想法吗?
P.S:如果您想知道为什么不调用 connect() 函数,那是因为它是通过 unity 的新 UI 系统调用的。
【问题讨论】:
-
您尝试分配字符串的 bool 属性位于哪一行?
-
包括堆栈跟踪。哪一行导致了错误。
-
能否给我们完整的错误信息,尤其是上面哪几行抛出了异常。
标签: c# unity3d error-handling