Advertisement
Guest User

My MenuHandler Script

a guest
Feb 20th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.55 KB | None | 0 0
  1. using System.Collections;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4.  
  5. public class MenuHandler : MonoBehaviour
  6. {
  7.  
  8.     string difficulty;
  9.     [SerializeField] GameObject difficultyPanel;
  10.     [SerializeField] CustomDropdown dropdown;
  11.     Animator diffPanelAnim;
  12.     [SerializeField] Text currentDifficultyText;
  13.     Button difficultyButton;
  14.  
  15.     private void Start()
  16.     {
  17.         difficultyButton = difficultyPanel.transform.parent.transform.GetChild(2).GetComponent<Button>();
  18.         //currentDifficultyText = difficultyPanel.transform.GetChild(0).GetChild(2).GetChild(1).GetComponent<Text>();
  19.         diffPanelAnim = difficultyPanel.GetComponent<Animator>();
  20.         ChangeDifficultyText(DifficultyManager.currentDifficulty);
  21.     }
  22.  
  23.     IEnumerator ChangeDifficultyText(DifficultyManager.Difficulty newDifficulty)
  24.     {
  25.         difficulty = newDifficulty.ToString();
  26.         if (difficulty == "Easy")
  27.         {
  28.             print("changing text to easy");
  29.             currentDifficultyText.text = "Easy";
  30.         }
  31.         else
  32.         {
  33.             print("changing text to normal");
  34.             currentDifficultyText.text = "Normal";
  35.         }
  36.         CloseDifficultyPanel();
  37.         yield return new WaitForSeconds(1.5f);
  38.         difficultyButton.interactable = true;
  39.     }
  40.  
  41.     public void ChoseEasyDifficulty()
  42.     {
  43.         new DifficultyManager(DifficultyManager.Difficulty.Easy);
  44.         StartCoroutine(ChangeDifficultyText(DifficultyManager.Difficulty.Easy));
  45.     }
  46.  
  47.     public void ChoseNormalDifficulty()
  48.     {
  49.         new DifficultyManager(DifficultyManager.Difficulty.Normal);
  50.         StartCoroutine(ChangeDifficultyText(DifficultyManager.Difficulty.Normal));
  51.     }
  52.  
  53.     public void CloseDifficultyPanel()
  54.     {
  55.         diffPanelAnim.SetTrigger("CloseDifWindow");
  56.         Invoke("DeactivateDiffPanel", 0.5f);
  57.     }
  58.  
  59.     private void DeactivateDiffPanel()
  60.     {
  61.         difficultyPanel.SetActive(false);
  62.     }
  63.  
  64.     public void OpenDifficultyPanel()
  65.     {
  66.         difficultyPanel.SetActive(true);
  67.         diffPanelAnim.SetTrigger("OpenDifWindow");
  68.     }
  69.  
  70.     public void ChoseDifficulty()
  71.     {
  72.         switch(dropdown.GetSelectedOption())
  73.         {
  74.             case "EASY":
  75.                 print("Chose easy difficulty");
  76.                 ChoseEasyDifficulty();
  77.                 break;
  78.             case "NORMAL":
  79.                 print("Chose normal difficulty");
  80.                 ChoseNormalDifficulty();
  81.                 break;
  82.         }
  83.     }
  84.  
  85.     public void QuitGame()
  86.     {
  87.         Application.Quit();
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement