【发布时间】:2016-11-18 20:18:55
【问题描述】:
以下脚本是我开始编写的,它需要一个 TextAsset 并拆分行并将其与各种字符串进行比较。但是我的检查功能只返回假。有什么我遗漏的主要内容吗,Unity 没有抛出任何错误,所以我不确定如何解决这个问题。
internal sealed class Checker {
private string AssetType(TextAsset fileToBeChecked) {
string[] line = fileToBeChecked.text.Split (new char[] { '\n' });
return line [0];
}
public bool isItem(TextAsset file) {
string type = AssetType (file).ToLower ();
if (type == "helmet" || type == "cuirass" || type == "gauntlets" || type == "gloves" || type == "boots" || type == "leggings" || type == "shield" || type == "robes" || type == "shirt" || type == "pants" || type == "shoes" || type == "hood" || type == "staff" || type == "stave" || type == "sword" || type == "greatsword" || type == "dagger" || type == "mace" || type == "warhammer" || type == "axe" || type == "waraxe" || type == "bow" || type == "misc") {
return true;
} else {
return false;
}
}
}
}
我的测试文件如下:
Helmet
1
Dragon's Vale
0
10
0
14
1280
调试后
【问题讨论】:
-
那你调试的时候
type是什么? -
这应该很容易使用调试器发现。我们不知道
AssetType(file).ToLower()返回什么,因为我们不知道您的上下文。那么我们怎么知道为什么条件永远不会通过呢? -
@EvanTrimboli 包含信息状态头盔的文件,当我拥有该功能时,在拉动它后给我价值,它说头盔。但是当它与 "helmet" 相比时,它返回 false。
-
显然不是,否则会匹配。
-
请只发布重现问题所需的代码。好像 isEnchantment() 和 isSpell() 无关,可以去掉。