Advertisement
JohnsterSpaceProgram

BFNS Remastered Main Menu Script

Oct 3rd, 2021
1,545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.38 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. using UnityEngine.SceneManagement;
  5. using TMPro;
  6.  
  7. public class MainMenu : MonoBehaviour
  8. {
  9.     // Start is called before the first frame update
  10.     public void Start()
  11.     {
  12.         if (!PlayerPrefs.HasKey("VolumeLevel"))
  13.         {
  14.             PlayerPrefs.SetFloat("VolumeLevel", 1f);
  15.         }
  16.         if (!PlayerPrefs.HasKey("DayNightMode"))
  17.         {
  18.             PlayerPrefs.SetString("DayNightMode", "Auto");
  19.         }
  20.         AudioListener.volume = PlayerPrefs.GetFloat("VolumeLevel");
  21.         UpdatePlatformLogo();
  22.         Cursor.lockState = CursorLockMode.None;
  23.         Cursor.visible = true;
  24.         Time.timeScale = 1f;
  25.         if (PlayerPrefs.GetInt("AchStartingOut") == 1 & PlayerPrefs.GetInt("AchNotebookCollectingMachine") == 1 & PlayerPrefs.GetInt("AchBaldiIsBroken") == 1 & PlayerPrefs.GetInt("AchPlaytimeScissorsSad") == 1 & PlayerPrefs.GetInt("AchCampingIsFun") == 1 & PlayerPrefs.GetInt("AchFasterThanTime") == 1) //If the player got every other acheivement
  26.         {
  27.             if (PlayerPrefs.GetInt("AchYouFoundThemAll") == 0) //Unlock the you've found them all achievement
  28.             {
  29.                 PlayerPrefs.SetInt("AchYouFoundThemAll", 1);
  30.                 achievementManager.EarnAchievement(6);
  31.                 mainMenuAudio.PlayOneShot(achievementEarn);
  32.             }
  33.         }
  34.     }
  35.  
  36.     public void Update()
  37.     {
  38.         if (!mainMenuAudio.isPlaying)
  39.         {
  40.             mainMenuAudio.PlayOneShot(mainMenuMusic);
  41.         }
  42.     }
  43.  
  44.     public void UpdatePlatformLogo()
  45.     {
  46.         if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor) //If the mod is currently being played on Windows (in either the player or unity editor)
  47.         {
  48.             logoImage.sprite = logoSprites[0]; //Display the Windows edition of the logo
  49.         }
  50.         else if (Application.platform == RuntimePlatform.OSXPlayer) //If the mod is currently being played on MacOS
  51.         {
  52.             logoImage.sprite = logoSprites[1]; //Display the MacOS edition of the logo
  53.         }
  54.         else if (Application.platform == RuntimePlatform.LinuxPlayer) //If the mod is currently being played on Linux
  55.         {
  56.             logoImage.sprite = logoSprites[2]; //Display the Linux edition of the logo
  57.         }
  58.         else if (Application.platform == RuntimePlatform.WebGLPlayer) //If the mod is currently being played on WebGL (browser version)
  59.         {
  60.             logoImage.sprite = logoSprites[3]; //Display the WebGL edition of the logo
  61.         }
  62.         else if (Application.platform == RuntimePlatform.Android) //If the mod is currently being played on a device running Android
  63.         {
  64.             logoImage.sprite = logoSprites[4]; //Display the Android edition of the logo
  65.         }
  66.         else if (Application.platform == RuntimePlatform.XboxOne) //UNUSED If the mod is currently being played on an Xbox One console
  67.         {
  68.             logoImage.sprite = logoSprites[5]; //Display the Xbox One edition of the logo
  69.         }
  70.         else if (Application.platform == RuntimePlatform.PS4) //UNUSED If the mod is currently being played on a Playstation 4 console
  71.         {
  72.             logoImage.sprite = logoSprites[6]; //Display the Playstation 4 edition of the logo
  73.         }
  74.         else if (Application.platform == RuntimePlatform.Switch) //UNUSED If the mod is currently being played on a Nintendo Switch console
  75.         {
  76.             logoImage.sprite = logoSprites[7]; //Display the Nintendo Switch edition of the logo
  77.         }
  78.     }
  79.  
  80.     public void SetScreenId(int id)
  81.     {
  82.         StartCoroutine(ShowScreenDelay(id));
  83.     }
  84.  
  85.     public void SetScreenIdAlt(int id)
  86.     {
  87.         StartCoroutine(ShowScreenDelayAlt(id));
  88.     }
  89.  
  90.     public void PlayCamAnimation(string animClipName)
  91.     {
  92.         menuCamAnim.Play(animClipName);
  93.     }
  94.  
  95.     public void SetShowDelay(float seconds)
  96.     {
  97.         showDelay = seconds;
  98.     }
  99.  
  100.     public IEnumerator ShowScreenDelay(int locId)
  101.     {
  102.         mainMenuScreens[0].SetActive(false);
  103.         yield return new WaitForSeconds(showDelay);
  104.         mainMenuScreens[locId].SetActive(true);
  105.     }
  106.  
  107.     public IEnumerator ShowScreenDelayAlt(int locId)
  108.     {
  109.         mainMenuScreens[locId].SetActive(false);
  110.         yield return new WaitForSeconds(showDelay);
  111.         mainMenuScreens[0].SetActive(true);
  112.     }
  113.  
  114.     public void QuitGame() //Quit the game
  115.     {
  116.         Application.Quit();
  117.     }
  118.  
  119.     public void ResetData() //Reset the player's data and quit the game
  120.     {
  121.         Debug.Log("Data Has Been Reset!");
  122.  
  123.         PlayerPrefs.DeleteKey("BaldiShirtColor");
  124.         PlayerPrefs.DeleteKey("BaldiPantsColor");
  125.         PlayerPrefs.DeleteKey("BaldiEyeColor");
  126.         PlayerPrefs.DeleteKey("BaldiActiveDecal");
  127.  
  128.         PlayerPrefs.DeleteKey("AchStartingOut");
  129.         PlayerPrefs.DeleteKey("AchNotebookCollectingMachine");
  130.         PlayerPrefs.DeleteKey("AchBaldiIsBroken");
  131.         PlayerPrefs.DeleteKey("AchPlaytimeScissorsSad");
  132.         PlayerPrefs.DeleteKey("AchCampingIsFun");
  133.         PlayerPrefs.DeleteKey("AchFasterThanTime");
  134.         PlayerPrefs.DeleteKey("AchYouFoundThemAll");
  135.  
  136.         PlayerPrefs.DeleteKey("TurnSensitivity");
  137.         PlayerPrefs.DeleteKey("VolumeLevel");
  138.         PlayerPrefs.DeleteKey("FpsEnabled");
  139.         PlayerPrefs.DeleteKey("MinimapEnabled");
  140.         PlayerPrefs.DeleteKey("DayNightMode");
  141.         PlayerPrefs.DeleteKey("UpdatedFirstPrizeSprites");
  142.         PlayerPrefs.DeleteKey("YctpPlayerPortrait");
  143.  
  144.         PlayerPrefs.DeleteKey("ForwardKey");
  145.         PlayerPrefs.DeleteKey("BackwardsKey");
  146.         PlayerPrefs.DeleteKey("LeftKey");
  147.         PlayerPrefs.DeleteKey("RightKey");
  148.         PlayerPrefs.DeleteKey("RunningKey");
  149.  
  150.         PlayerPrefs.DeleteKey("Item1Found");
  151.         PlayerPrefs.DeleteKey("Item2Found");
  152.         PlayerPrefs.DeleteKey("Item3Found");
  153.         PlayerPrefs.DeleteKey("Item4Found");
  154.         PlayerPrefs.DeleteKey("Item5Found");
  155.         PlayerPrefs.DeleteKey("Item6Found");
  156.         PlayerPrefs.DeleteKey("Item7Found");
  157.         PlayerPrefs.DeleteKey("Item8Found");
  158.         PlayerPrefs.DeleteKey("Item9Found");
  159.         PlayerPrefs.DeleteKey("Item10Found");
  160.         PlayerPrefs.DeleteKey("Item11Found");
  161.         PlayerPrefs.DeleteKey("Item12Found");
  162.         PlayerPrefs.DeleteKey("Item13Found");
  163.         PlayerPrefs.DeleteKey("Item14Found");
  164.  
  165.         PlayerPrefs.DeleteKey("Gamemode");
  166.         PlayerPrefs.DeleteKey("ChosenPlayer");
  167.         PlayerPrefs.DeleteKey("EndlessNotebooks");
  168.         PlayerPrefs.DeleteKey("PlayingAsHacker");
  169.  
  170.         Application.Quit();
  171.     }
  172.  
  173.     public void SetGamemode(string gamemode)
  174.     {
  175.         PlayerPrefs.SetString("Gamemode", gamemode);
  176.         chooseText.text = "Choose A Player!";
  177.  
  178.         for (int i = 0; i < modeButtons.Length; i++)
  179.         {
  180.             modeButtons[i].SetActive(false);
  181.         }
  182.         for (int j = 0; j < playerButtons.Length; j++)
  183.         {
  184.             playerButtons[j].SetActive(true);
  185.         }
  186.     }
  187.  
  188.     public void SetPlayer(string playerName)
  189.     {
  190.         PlayerPrefs.SetString("ChosenPlayer", playerName);
  191.     }
  192.  
  193.     public void LoadLevel(string levelName)
  194.     {
  195.         SceneManager.LoadSceneAsync(levelName);
  196.     }
  197.  
  198.     public void EnableLoadingScreen(int loadScreenId)
  199.     {
  200.         //Enable the set loading screen (5 is school loading screen, 6 is loading screen for other modes)
  201.         mainMenuScreens[loadScreenId].SetActive(true);
  202.     }
  203.  
  204.     public void ResetPlayScreen()
  205.     {
  206.         for (int i = 0; i < modeButtons.Length; i++)
  207.         {
  208.             modeButtons[i].SetActive(true);
  209.         }
  210.         for (int j = 0; j < playerButtons.Length; j++)
  211.         {
  212.             playerButtons[j].SetActive(false);
  213.         }
  214.         chooseText.text = "Select A Gamemode!";
  215.     }
  216.  
  217.     public void OpenLink(string url)
  218.     {
  219.         Application.OpenURL(url);
  220.     }
  221.  
  222.     public Image logoImage;
  223.     public Sprite[] logoSprites;
  224.     public Transform[] cameraTransforms;
  225.  
  226.     public GameObject[] mainMenuScreens;
  227.     public AudioSource mainMenuAudio;
  228.     public AudioClip mainMenuMusic;
  229.  
  230.     public GameObject[] modeButtons;
  231.     public GameObject[] playerButtons;
  232.     public TMP_Text chooseText;
  233.  
  234.     public float showDelay;
  235.     public Animator menuCamAnim;
  236.     public AudioClip achievementEarn;
  237.     public Achievement achievementManager;
  238. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement