void Awake() { if (instance != null && instance != this) { Destroy(this.gameObject); return; } else { instance = this; } DontDestroyOnLoad(this.gameObject); }
void Awake() { CharacterHolder = GameObject.Find("CharacterSpritesHolder").GetComponent <CharacterSpritesHolder>(); HighscoresScreen = transform.Find("HighscoresScreen").gameObject; HighscoresText = HighscoresScreen.transform.Find("RankValues").GetComponent <Text>(); CharacterSelectionImage = GameObject.Find("Character").GetComponent <Image>(); CoinsText = GameObject.Find("Coins").GetComponent <Text>(); UnlockButtonGO = GameObject.Find("Unlock"); UnlockButton = UnlockButtonGO.GetComponent <Button>(); UnlockButtonGO.SetActive(false); CharacterUnlock = new bool[CharacterHolder.CharacterSprites.Length]; NeededCoins = UnlockButtonGO.transform.Find("NeededCoins").GetComponent <Text>(); if (PlayerPrefs.HasKey("CharacterIndex")) { CharacterIndex = PlayerPrefs.GetInt("CharacterIndex"); CharacterSelectionImage.sprite = CharacterHolder.CharacterSprites[CharacterIndex]; } else { CharacterIndex = 0; PlayerPrefs.SetInt("CharacterIndex", 0); PlayerPrefs.Save(); CharacterSelectionImage.sprite = CharacterHolder.CharacterSprites[CharacterIndex]; } NeededCoins.text = CharacterHolder.CoinCost[CharacterIndex].ToString(); if (PlayerPrefs.HasKey("Coins")) { Coins = PlayerPrefs.GetInt("Coins"); CoinsText.text = Coins.ToString(); } else { Coins = 0; PlayerPrefs.SetInt("Coins", 0); PlayerPrefs.Save(); CoinsText.text = Coins.ToString(); } string tChar = ""; for (int i = 0; i < CharacterUnlock.Length; i++) { tChar = "Character" + i; if (!PlayerPrefs.HasKey(tChar)) { if (i != 0) { PlayerPrefsX.SetBool(tChar, false); } else { PlayerPrefsX.SetBool(tChar, true); } PlayerPrefs.Save(); } CharacterUnlock[i] = PlayerPrefsX.GetBool(tChar); } if (CharacterUnlock[CharacterIndex]) { UnlockButtonGO.SetActive(false); } else { UnlockButtonGO.SetActive(true); } if (PlayerPrefs.HasKey("1.")) { HighscoreNumbers[0] = PlayerPrefs.GetInt("1."); } else { HighscoreNumbers[0] = 0; PlayerPrefs.SetInt("1.", 0); } if (PlayerPrefs.HasKey("2.")) { HighscoreNumbers[1] = PlayerPrefs.GetInt("2."); } else { HighscoreNumbers[1] = 0; PlayerPrefs.SetInt("2.", 0); } if (PlayerPrefs.HasKey("3.")) { HighscoreNumbers[2] = PlayerPrefs.GetInt("3."); } else { HighscoreNumbers[2] = 0; PlayerPrefs.SetInt("3.", 0); } if (PlayerPrefs.HasKey("4.")) { HighscoreNumbers[3] = PlayerPrefs.GetInt("4."); } else { HighscoreNumbers[3] = 0; PlayerPrefs.SetInt("4.", 0); } if (PlayerPrefs.HasKey("5.")) { HighscoreNumbers[4] = PlayerPrefs.GetInt("5."); } else { HighscoreNumbers[4] = 0; PlayerPrefs.SetInt("5.", 0); } string tRankValues = ""; for (int i = 0; i < HighscoreNumbers.Length; i++) { tRankValues += HighscoreNumbers[i]; if (i < HighscoreNumbers.Length - 1) { tRankValues += "\n"; } } HighscoresText.text = tRankValues; }
void Awake() { //Level = BlockLoopTriggerAtLevel; //PlayerPrefs.DeleteAll(); CalculateVariables(); CharacterHolder = GameObject.Find("CharacterSpritesHolder").GetComponent <CharacterSpritesHolder>(); PlayerSprite = CharacterHolder.CharacterSprites[PlayerPrefs.GetInt("CharacterIndex")]; ColorPalette = new Color[(int)BlocksToFinish + 1]; for (int i = 0; i < ColorPalette.Length; i++) { while (ColorPalette[i] == new Color() || ColorPalette[i] == Color.black || (ColorPalette[i].r + ColorPalette[i].g + ColorPalette[i].b) < 1.5f) { ColorPalette[i] = new Color(Random.Range(0.01f, 1f), Random.Range(0.01f, 1f), Random.Range(0.01f, 1f)); } float tThisColorSum = ColorPalette[i].r + ColorPalette[i].g + ColorPalette[i].b; float tOtherColorSum = 0f; for (int i2 = 0; i2 < i; i2++) { tOtherColorSum = ColorPalette[i2].r + ColorPalette[i2].g + ColorPalette[i2].b; if (Mathf.Abs(tThisColorSum - tOtherColorSum) < 0.25f) { ColorPalette[i] = Color.black; i--; break; } } } GameObject tPause = GameObject.Find("Pause"); GameObject tMute = GameObject.Find("Music"); PauseButton = tPause.GetComponent <Button>(); MuteButton = tMute.GetComponent <Button>(); PlayerJump = transform.Find("PlayerJumpSound").GetComponent <AudioSource>(); PlayerDie = transform.Find("PlayerDieSound").GetComponent <AudioSource>(); EnemyDie = transform.Find("EnemyDieSound").GetComponent <AudioSource>(); EnemySpawn = transform.Find("EnemySpawnSound").GetComponent <AudioSource>(); Special = transform.Find("SpecialSound").GetComponent <AudioSource>(); Coins = PlayerPrefs.GetInt("Coins"); GameObject MiddleTextGO = GameObject.Find("MiddleText"); MiddleText = MiddleTextGO.GetComponent <Text>(); MiddleTextOutline = MiddleTextGO.GetComponent <Outline>(); DarkenerGO = GameObject.Find("Darkener"); Darkener = DarkenerGO.GetComponent <Image>(); Darkener.CrossFadeAlpha(0f, 0f, true); DarkenerGO.SetActive(false); bool tMuteBool = PlayerPrefsX.GetBool("Mute"); PlayerJump.mute = tMuteBool; PlayerDie.mute = tMuteBool; EnemyDie.mute = tMuteBool; EnemySpawn.mute = tMuteBool; Special.mute = tMuteBool; Quotes.Add("I think you're shagedelic baby! You're switched on! You're smashing!"); Quotes.Add("Smashing Baby! When this ship comes a' rockin', don't come a' knockin', baby!"); Quotes.Add("It's freedom, baby, yeah!"); Quotes.Add("It seems the tables have turned again, Dr. Evil."); Quotes.Add("Its time to swing, baby."); Quotes.Add("Ooo, Behave!"); Quotes.Add("Yeah, baby, yeah!"); Quotes.Add("What say, you, we go out on the town and swing, baby? Yeah!"); Quotes.Add("Let's hop on the good foot and do the bad thing."); Quotes.Add("Oops. I did it again, baby."); Quotes.Add("Yeah Baby."); Quotes.Add("Very Shagadelic, baby, yeah."); }