//Saving data public void SaveGame() { //Saving score to leaderboard menuManager.GetComponent <GPSManager>().PublishScoreToLeaderboard(score); //Loading data and this same creating a save object PlayerSaveData psd = SaveManager.LoadData(); //Checking is new record set if (score > psd.bestScore) { //Saving score to save file psd.bestScore = score; } //Updating money value psd.money = money; psd.gamesPlayed++; //Saving data SaveManager.SaveData(psd); CheckGamesPlayed(psd.gamesPlayed); if (psd.money >= 100) { GPSManager.UnlockAchievement(GPGSIds.achievement_have_at_least_100_bucks); } try { this.GetComponent <GPSManager>().OpenSave(true); } catch (Exception e) { } }
public void TutorialMenuButtonClicked() { if (canInteract) { ButtonClickSound(); canInteract = false; PlayerSaveData psd = SaveManager.LoadData(); GPSManager.UnlockAchievement(GPGSIds.achievement_beginner_is_here); StartCoroutine("ToggleTutorialPanel", false); } }
//Detecting collision with trigger void OnTriggerEnter2D(Collider2D other) { //Checking is that deadLine if (other.CompareTag("DeadLine")) { audioManager.GetComponent <AudioManagerScript>().DeathLane.Play(); GPSManager.UnlockAchievement(GPGSIds.achievement_get_burnt); //Handheld.Vibrate(); StartCoroutine("KillPlayer"); } //Checking is that boost else if (other.CompareTag("BoostJump") && activeBoostID == 0) { audioManager.GetComponent <AudioManagerScript>().BubbleDestroy.Play(); GPSManager.UnlockAchievement(GPGSIds.achievement_boost_up); StartCoroutine(BoostJump(other, false)); } else if (other.CompareTag("BoostMagnet") && activeBoostID == 0) { audioManager.GetComponent <AudioManagerScript>().BubbleDestroy.Play(); GPSManager.UnlockAchievement(GPGSIds.achievement_boost_up); StartCoroutine("BoostMagnet", other); } else if (other.CompareTag("BoostMultipler") && activeBoostID == 0) { audioManager.GetComponent <AudioManagerScript>().BubbleDestroy.Play(); GPSManager.UnlockAchievement(GPGSIds.achievement_boost_up); StartCoroutine("BoostMultipler", other); } else if (other.CompareTag("BoostShield") && activeBoostID == 0) { audioManager.GetComponent <AudioManagerScript>().BubbleDestroy.Play(); GPSManager.UnlockAchievement(GPGSIds.achievement_boost_up); StartCoroutine("BoostShield", other); } else if (other.CompareTag("Coin")) { CollectCoin(other.gameObject); } else if (other.CompareTag("Crystal")) { CollectCrystal(other.gameObject); } //Checking is that best score lane else if (other.CompareTag("ScoreLane")) { audioManager.GetComponent <AudioManagerScript>().RecordLane.Play(); Instantiate(scoreLaneDestroyEffect, new Vector3(0f, other.gameObject.transform.position.y, 0f), Quaternion.identity); Destroy(other.gameObject); Handheld.Vibrate(); menuManager.GetComponent <MenuManagerScript>().ChangeScoreColor(false); } }
//Checks achievements public void CheckGamesPlayed(int gamesPlayed) { if (gamesPlayed >= 100) { GPSManager.UnlockAchievement(GPGSIds.achievement_play_100_games); } else if (gamesPlayed >= 10) { GPSManager.UnlockAchievement(GPGSIds.achievement_play_10_games); } if (gamesPlayed >= 1) { GPSManager.UnlockAchievement(GPGSIds.achievement_play_1_game); } }
//Gets prize public void GetPrize() { ButtonClickSound(); if (canInteract && IsPrizeReady()) { audioManager.GetComponent <AudioManagerScript>().IAPbuy.Play(); canInteract = false; microtransactionsAnimator.SetTrigger("getPrize"); PlayerSaveData psd = SaveManager.LoadData(); psd.freePrizeCollectedDate = DateTime.Now; microtransactionsSpecialMoneyAnimation.SetActive(false); microtransactionsSpecialMoneyAnimation.SetActive(true); microtransactionsMoneyAnimation.SetActive(false); microtransactionsMoneyAnimation.SetActive(true); psd.specialMoney += UnityEngine.Random.Range(1, 3); psd.money += UnityEngine.Random.Range(5, 11); freePrizeDate = DateTime.Now; SaveManager.SaveData(psd); UpdateMoneyInMenu(psd.money, psd.specialMoney); gameManager.GetComponent <GameManagerScript>().money = psd.money; UpdateMoneyInGame(psd.money); CheckFreePrize(); canInteract = true; if (psd.money >= 100) { GPSManager.UnlockAchievement(GPGSIds.achievement_have_at_least_100_bucks); } if (psd.specialMoney >= 100) { GPSManager.UnlockAchievement(GPGSIds.achievement_have_at_least_100_crystals); } try { this.GetComponent <GPSManager>().OpenSave(true); } catch (Exception e) { } } }
private void ShareCallBack(IShareResult result) { if (result.Error != null || result.Cancelled) { StartCoroutine(this.GetComponent <MenuManagerScript>().ToggleInfoPanel("Something went wrong while posting... :(", true)); } else { PlayerSaveData psd = SaveManager.LoadData(); if (!psd.isSharedPost) { psd.isSharedPost = true; psd.specialMoney += 100; GPSManager.UnlockAchievement(GPGSIds.achievement_have_at_least_100_crystals); this.GetComponent <MenuManagerScript>().UpdateMoneyInMenu(psd.money, psd.specialMoney); SaveManager.SaveData(psd); StartCoroutine(this.GetComponent <MenuManagerScript>().ToggleInfoPanel("Successfully got 100 crystals!", true)); } } }
//Adding and saving money after purchase public void AddPurchasedMoney(int ammount, bool isSpecial) { audioManager.GetComponent <AudioManagerScript>().IAPbuy.Play(); PlayerSaveData psd = SaveManager.LoadData(); if (isSpecial) { psd.specialMoney += ammount; if (psd.specialMoney >= 100) { GPSManager.UnlockAchievement(GPGSIds.achievement_have_at_least_100_crystals); } } else { psd.money += ammount; if (psd.specialMoney >= 100) { GPSManager.UnlockAchievement(GPGSIds.achievement_have_at_least_100_bucks); } } //Saving data SaveManager.SaveData(psd); menuManager.GetComponent <MenuManagerScript>().UpdateMoneyInMenu(psd.money, psd.specialMoney); try { this.GetComponent <GPSManager>().OpenSave(true); } catch (Exception e) { } }
//When player pressed button to buy/select character public void CharactersButtonClicked(int id, bool owned, bool special) { if (canInteract) { ButtonClickSound(); canInteract = false; int cost = this.GetComponent <CharactersDataScript>().characterCost[id]; //Checking that is player having that character if (owned) { //Finding player GameObject player = GameObject.Find("Player"); //Setting a new sprite player.GetComponent <SpriteRenderer>().sprite = this.GetComponent <CharactersDataScript>().characterSprite[id]; //Saving new selected player id this.GetComponent <CharactersDataScript>().choosedCharacterID = id; PlayerSaveData psd = SaveManager.LoadData(); psd.choosedCharacter = id; SaveManager.SaveData(psd); StartCoroutine("OpenMainMenu", 2); try { this.GetComponent <GPSManager>().OpenSave(true); } catch (Exception e) { } } else { if (special) { PlayerSaveData psd = SaveManager.LoadData(); //Checking is player have enought money to buy character if (psd.specialMoney >= cost) { //Finding player GameObject player = GameObject.Find("Player"); //Setting a new sprite player.GetComponent <SpriteRenderer>().sprite = this.GetComponent <CharactersDataScript>().characterSprite[id]; //Saving new selected player id and money this.GetComponent <CharactersDataScript>().choosedCharacterID = id; this.GetComponent <CharactersDataScript>().ownedCharacters[id] = true; psd.specialMoney -= cost; psd.choosedCharacter = id; psd.ownedCharacters[id] = true; SaveManager.SaveData(psd); UpdateMoneyInMenu(psd.money, psd.specialMoney); StartCoroutine("OpenMainMenu", 2); GPSManager.UnlockAchievement(GPGSIds.achievement_get_first_special_character); try { this.GetComponent <GPSManager>().OpenSave(true); } catch (Exception e) { } } else { canInteract = true; } } else { PlayerSaveData psd = SaveManager.LoadData(); //Checking is player have enought money to buy character if (psd.money >= cost) { //Finding player GameObject player = GameObject.Find("Player"); //Setting a new sprite player.GetComponent <SpriteRenderer>().sprite = this.GetComponent <CharactersDataScript>().characterSprite[id]; //Saving new selected player id and money this.GetComponent <CharactersDataScript>().choosedCharacterID = id; this.GetComponent <CharactersDataScript>().ownedCharacters[id] = true; psd.money -= cost; psd.choosedCharacter = id; psd.ownedCharacters[id] = true; int y = 0; foreach (bool x in psd.ownedCharacters) { if (x) { y++; } } if (y >= 10) { GPSManager.UnlockAchievement(GPGSIds.achievement_get_10_characters); } else if (y >= 2) { GPSManager.UnlockAchievement(GPGSIds.achievement_get_first_character); } SaveManager.SaveData(psd); gameManager.GetComponent <GameManagerScript>().money = psd.money; UpdateMoneyInMenu(psd.money, psd.specialMoney); StartCoroutine("OpenMainMenu", 2); try { this.GetComponent <GPSManager>().OpenSave(true); } catch (Exception e) { } } else { canInteract = true; } } } } }