public class LearningCurve : MonoBehaviour
{
public bool pureOfHeart = true;
public bool hasSecretIncantation = false;
public string rareItem = "RelicStone";
// Start is called before the first frame update
void Start()
{
OpenTreasureChamber();
}
public void OpenTreasureChamber()
{
if (pureOfHeart && rareItem == "RelicStone")
{
if(!hasSecretIncantation)
{
Debug.Log("You have the spirit,but not the knowledge.");
}
else
{
Debug.Log("The treasure is yours,worthy hero");
}
}
else
{
Debug.Log("Come back when you have what it takes");
}
}
}
Come back when you have what it takes
书上是
You have the spirit,but not the knowledge.
首先要理解C#中是怎么通过==来比较两个字符串是否相等
==操作是先判断两者内存地址是否相同,相同则返回true,不同,则继续判断值是否相同。
所以你这里rareItem == "RelicStone"为什么是false,请仔细检查Inspector面板,是否在Editor中对变量进行了修改