haobo wei 3 недель назад
Родитель
Сommit
0b65f2d3e8
2 измененных файлов с 16 добавлено и 4 удалено
  1. 5 0
      Assets/GAME/Scripts/UI/GameUI.cs
  2. 11 4
      Assets/Scripts/MathQuizManager.cs

+ 5 - 0
Assets/GAME/Scripts/UI/GameUI.cs

@@ -18,6 +18,7 @@ public class GameUI : MonoBehaviour
   private bool _isStop;
   private int _tempSettingID;
   private int _settingID;
+  private MathQuizManager quizManager;
 
   private void OnEnable()
   {
@@ -37,6 +38,8 @@ public class GameUI : MonoBehaviour
     print("SETTING ID - " + _settingID);
     print("_tempSetting ID - " + _tempSettingID);
     levelDisplayText.SetText(I2.Loc.LocalizationManager.GetTranslation("Level") + " " + (ComponentsManager.PlayerData.GetLevel + 1));
+    quizManager = FindObjectOfType<MathQuizManager>();
+    if (quizManager != null) quizManager.ShowQuizUI(false); // 游戏未开始时隐藏
   }
 
   public void CoiAudioPlay()
@@ -62,6 +65,7 @@ public class GameUI : MonoBehaviour
       SetEndEvent();
       PlayerPrefs.DeleteKey("_stageLevel");
       _isStop = true;
+      if (quizManager != null) quizManager.ShowQuizUI(false); // 胜利时隐藏
     }
   }
 
@@ -72,6 +76,7 @@ public class GameUI : MonoBehaviour
       loseWrapper.SetActive(true);
       _isStop = true;
       SetEndEvent();
+      if (quizManager != null) quizManager.ShowQuizUI(false); // 失败时隐藏
     }
   }
 

+ 11 - 4
Assets/Scripts/MathQuizManager.cs

@@ -29,17 +29,17 @@ public class MathQuizManager : MonoBehaviour
     private Vector3 lastEnemyPos;
     private int deathCount = 0;
 
-    void Start() { NewProblem(); UpdateCoin(); }
+    void Start() { NewProblem(); UpdateCoin(); ShowQuizUI(true); }
 
     void NewProblem()
     {
         int a = Random.Range(1, 11), b = Random.Range(1, 11);
-        if (Random.value < 0.5f) // 加法
+        if (Random.value < 0.5f)
         {
             currentAnswer = a + b;
             questionText.text = $"{a} + {b} = ?";
         }
-        else // 减法
+        else
         {
             if (b > a) (a, b) = (b, a);
             currentAnswer = a - b;
@@ -123,7 +123,6 @@ public class MathQuizManager : MonoBehaviour
         {
             Destroy(obj);
         }
-        // 新手引导
         if (!PlayerPrefs.HasKey("FirstQuizTutorial"))
         {
             PlayerPrefs.SetInt("FirstQuizTutorial", 1);
@@ -141,4 +140,12 @@ public class MathQuizManager : MonoBehaviour
             if (oldest) Destroy(oldest.gameObject);
         }
     }
+
+    // 新增:控制题目和答案的显示/隐藏
+    public void ShowQuizUI(bool show)
+    {
+        if (questionText) questionText.gameObject.SetActive(show);
+        foreach (var a in answers)
+            if (a && a.gameObject) a.gameObject.SetActive(show);
+    }
 }