一袭白衣梅子酒 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日

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教