private void Awake() { //Only 1 gameManager needs to persist through scene switches if (gameManager == null) { gameManager = this; DontDestroyOnLoad(this); } else if (this != gameManager) { Destroy(this.gameObject); } }
// Use this for initialization void Start() { smScript = GameObject.Find("SceneManager").GetComponent <SmScript> (); smScript.enabled = true; player = GameObject.Find("PlayerText").GetComponent <Text>(); character = GameObject.Find("CharacterText").GetComponent <Text> (); playerScore = GameObject.Find("PlayerHiScoreText").GetComponent <Text> (); input = GameObject.Find("InputPanel Cancel Option"); inputField = GameObject.Find("InputField Cancel Option").GetComponent <InputField> (); inputFirstTime = GameObject.Find("InputPanel First Time"); inputFieldFirst = GameObject.Find("InputField First Time").GetComponent <InputField> (); inputInnerPanel = GameObject.Find("InputPanel Cancel Option Inner Panel"); inputFirstInnerPanel = GameObject.Find("InputPanel First Time Inner Panel"); inputHint = GameObject.Find("PlaceholderCancelOption").GetComponent <Text>(); inputHintFirst = GameObject.Find("PlaceholderFirstTime").GetComponent <Text>(); playerList = GameObject.Find("Player Select Panel"); charList = GameObject.Find("Character Select Panel"); anim = GameObject.Find("AnimationSprite").GetComponent <Animator>(); charSelectButton = GameObject.Find("Char Select Button Text"); charSelButtonText = charSelectButton.GetComponent <Text> (); playerSelectButton = GameObject.Find("Player Select Button Text"); playerSelButtonText = playerSelectButton.GetComponent <Text> (); playerRemoveButton = GameObject.Find("Remove Player Button Text"); playerRemButtonText = playerRemoveButton.GetComponent <Text> (); cancelNewPlayerButton = GameObject.Find("Cancel New Player Button").GetComponent <Button> (); animWindow = GameObject.Find("Animation Window"); confirmPanel = GameObject.Find("Remove Player Panel"); confirmText = GameObject.Find("Remove Name Text").GetComponent <Text>(); newPlayerButton = GameObject.Find("New Player Button"); maxPlayerImage = GameObject.Find("Max Player Image"); lbButton = GameObject.Find("Leaderboard Button").GetComponent <Button>(); lbButton.onClick.AddListener(smScript.gameObject.GetComponent <SocialManager>().displayLeaderBoard); lbPanel = GameObject.Find("Leaderboard Button Cover"); loginInfoPanelIOS = GameObject.Find("Login Info Panel IOS"); loginInfoPanelCover = GameObject.Find("Login Panel Coverup"); loginInfoTextIOS = GameObject.Find("InfoPanel Text IOS").GetComponent <Text>(); lbIconAndroid = GameObject.Find("GPGS Icon Background"); lbIconIOS = GameObject.Find("GameCenter Icon Background"); fadeScript = GameObject.Find("Fade Image1").GetComponent <FadeController> (); fadeScript.fadeInMenu(); //Fade in the image inputMoveVector = new Vector3(13, 135, 0); inputFirstMoveVector = new Vector3(13, 165, 0); inputResetVector = new Vector3(13, 0, 0); inputFirstResetVector = new Vector3(13, 31, 0); source = GetComponent <AudioSource>(); cancellingNewPlayer = false; playedScrollSound = false; input.SetActive(false); //Turn off input field until needed inputFirstTime.SetActive(false); //Turn off first time input field until needed confirmPanel.SetActive(false); //Turn off panel until needed scoreTexts = new Text[10]; charTexts = new Text[10]; textNum = ""; charTextNum = ""; Time.timeScale = 1; smScript.resetShowingAd(); //Get number of saved players from playerprefs, or add entry if first time playing if (PlayerPrefs.HasKey("playersSaved")) { numOfPlayers = 10; playerNum = PlayerPrefs.GetInt("playersSaved"); if (playerNum >= 10) //Toggle button or image if max players are saved { newPlayerButton.SetActive(false); } else { maxPlayerImage.SetActive(false); } } else { PlayerPrefs.SetInt("playersSaved", 0); //Create PlayerPref entry if first time playing playerNum = 0; maxPlayerImage.SetActive(false); } playerTexts = new Text[numOfPlayers]; setupPlayerSelectWindow(); //Setup panels for selecting player and character setupCharSelectWindow(); //Set up High Score window for (int i = 0; i < scoreTexts.Length; i++) { scoreTexts [i] = GameObject.Find("Score" + (i + 1).ToString() + "Text").GetComponent <Text> (); //Get high scores from player prefs if (PlayerPrefs.HasKey("hallScore" + i.ToString())) { if (PlayerPrefs.GetInt("hallScore" + i.ToString()) == 0) { scoreTexts [i].text = ""; } else { scoreTexts [i].text = PlayerPrefs.GetString("hallName" + i.ToString()) + ": " + PlayerPrefs.GetInt("hallScore" + i.ToString()).ToString("N0") + " points"; //set text with score } } else { PlayerPrefs.SetInt("hallScore" + i.ToString(), 0); //Create playerpref entries if first time playing PlayerPrefs.SetString("hallName" + i.ToString(), ""); } } //Set up current player texts and player prefs keys, or assign if first time playing if (PlayerPrefs.HasKey("curPlayer")) { player.text = PlayerPrefs.GetString("curPlayer"); if (player.text == "") { playerScore.text = ""; noPlayer = true; } else { playerScore.text = player.text + "'s High Score: " + PlayerPrefs.GetInt("player" + PlayerPrefs.GetString(player.text) + "Score").ToString("N0"); } } else { player.text = ""; playerScore.text = ""; inputFirstTime.SetActive(true); //Turn on first time input field noPlayer = true; } if (PlayerPrefs.HasKey("curChar")) { character.text = PlayerPrefs.GetString("curChar"); } else { PlayerPrefs.SetString("curChar", char1); } updateAnim(); //Update the character animation for the current player if (player.text == "") //If there is no saved player, turn off animation until the player enters a name { anim.GetComponent <SpriteRenderer>().enabled = false; character.text = ""; } smScript.gameObject.GetComponent <SocialManager>().mScript = gameObject.GetComponent <MenuControl>(); SocialManager.sManager.mScript = gameObject.GetComponent <MenuControl> (); smScript.gameObject.GetComponent <ConnectionMonitor> ().mScript = gameObject.GetComponent <MenuControl>(); SocialManager.sManager.cmScript = smScript.gameObject.GetComponent <ConnectionMonitor> (); toggleLBButton(true); setLoginInfoPanelText(); setLBButtonIcon(); loginInfoPanelIOS.SetActive(false); loginInfoPanelCover.SetActive(false); if (smScript.ready) { smScript.checkAdStatus(); } }