一袭白衣梅子酒 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 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题