小编Jim*_*m N的帖子

如果声明不工作Unity C#

编辑:是的,我最近在python中编码,iv混合了两种语言之间的语法.感谢您的改进提示.

我的目标是让if语句工作并输出相应的normal,medium和hard.尽管GameDifficulty设置为2,但它输出的是硬而不是中等.我注意到它只输出最后一个if语句位.它真的很奇怪.

我将GameDifficulty定义为2.当我运行脚本时,Text11变为"硬"而不是"中".我不知道为什么会这样.

谢谢

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class DifficultyDisplayOnWinScreen : MonoBehaviour {
    public int GameDifficulty;
    public GameObject Text11;
    public string diffi;
    void Start () 
    {

        //GameDifficulty = DifficultyChooser.DifficultyNumber;
        GameDifficulty = 2;

    }

    void Update () 
    {
        //GameDifficulty = DifficultyChooser.DifficultyNumber;
        if (GameDifficulty == 3);
        {
            Text11.GetComponent<Text> ().text = "Normal";
        }       
        if (GameDifficulty == 2);
        {
            Text11.GetComponent<Text> ().text = "Medium";
        }
        if (GameDifficulty == 1);
        {
            Text11.GetComponent<Text> ().text = "Hard";
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

1
推荐指数
2
解决办法
285
查看次数

标签 统计

c# ×1

unity-game-engine ×1