一袭白衣梅子酒 2022-04-10 16:04 采纳率: 100%
浏览 35
已结题

Unity&&C#,简单选择问题,输出的Console调试日志和书上不一致

代码输出结果和《c#实践入门:快捷学习c#编程和unity游戏开发 第四版》书上的不匹配
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.

经过测试,发现判断rareItem == "RelicStone"的值为假,为什么会是假?
  • 写回答

3条回答 默认 最新

  • 就当作是我不吉利 2022-04-11 19:27
    关注

    检查一下unity的inspector面板的值,是否与代码的值相同。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 4月20日
  • 已采纳回答 4月12日
  • 创建了问题 4月10日

悬赏问题

  • ¥20 为什么安装CSiBridge时出现了这个问题,尝试了很多方法都不行,求详细操作步骤?
  • ¥15 鼠标右键,撤销删除 复制 移动,要怎样删除
  • ¥15 使用MATLAB进行余弦相似度计算加速
  • ¥15 服务器安装php5.6版本
  • ¥15 我想用51单片机和数码管做一个从0开始的计数表 我写了一串代码 但是放到单片机里面数码管只闪烁一下然后熄灭
  • ¥20 系统工程中,状态空间模型中状态方程的应用。请猛男来完整讲一下下面所有问题
  • ¥15 我想在WPF的Model Code中获取ViewModel Code中的一个参数
  • ¥15 arcgis处理土地利用道路 建筑 林地分类
  • ¥20 使用visual studio 工具用C++语音,调用openslsx库读取excel文件的sheet问题
  • ¥100 寻会做云闪付tn转h5支付链接的技术