/// <summary> /// Either select the character or open modal /// </summary> /// <param name="characterChoice">Index of the selected character</param> public void OnCharacterSelect(int characterChoice) { this.characterChoice = characterChoice; CharacterSelectionButton[] characterButtons = FindObjectsOfType <CharacterSelectionButton>(); Character selectedCharacter = characters[characterChoice]; string[] ownedCharacters = PlayerPrefsController.GetCharacters(); foreach (string ownedCharacter in ownedCharacters) { if (selectedCharacter.CharacterName == ownedCharacter) { BuyOrSelectCharacter(selectedCharacter.CharacterIndex); return; } } if (PlayerPrefsController.GetPoints() >= selectedCharacter.CharacterPointCost) { modalPanel.ShowPanelSuccess(); FixIsOnBug(characterButtons); } else { modalPanel.ShowPanelFail(); FixIsOnBug(characterButtons); } }
/// <summary> /// When game start set last active character as selected /// </summary> /// <param name="characterChoice">index of the character</param> private void SetCharacterOnStart(int characterChoice) { if (PlayerPrefsController.GetCharacters().Length == 0) { PlayerPrefsController.SetCharacter(0); PlayerPrefsController.SetCharacters("dudeWithBlueShirt"); BuyOrSelectCharacter(0); } else { BuyOrSelectCharacter(characterChoice); } }
private void Start() { // PlayerPrefs.DeleteAll(); string[] ownedCharacters = PlayerPrefsController.GetCharacters(); costs = FindObjectsOfType <Cost>(); foreach (Cost cost in costs) { cost.HidePointCost(ownedCharacters); } globalManager = FindObjectOfType <GlobalManager>(); modalPanel = FindObjectOfType <ModalPanel>(); player = GameObject.FindGameObjectWithTag(Player); characterSelection = GameObject.FindGameObjectWithTag(CharacterSelection); informationPanel = GameObject.FindGameObjectWithTag(InformationPanel); points = FindObjectOfType <Points>(); SetCharacterOnStart(PlayerPrefsController.GetCharacter()); }
/// <summary> /// If character isn't inside of playerPrefs buy it otherwise select /// </summary> /// <param name="characterChoice">Index of the clicked character</param> private void BuyOrSelectCharacter(int characterChoice) { CharacterSelectionButton[] characterButtons = FindObjectsOfType <CharacterSelectionButton>(); Character selectedCharacter = characters[characterChoice]; string[] ownedCharacters = PlayerPrefsController.GetCharacters(); if (ownedCharacters.Contains(selectedCharacter.CharacterName) == false) { int newPointsTotal = PlayerPrefsController.GetPoints() - selectedCharacter.CharacterPointCost; PlayerPrefsController.SetPoints(newPointsTotal); points.DisplayPoints(); PlayerPrefsController.SetCharacters(selectedCharacter.CharacterName); string[] updatedOwnedCharacters = PlayerPrefsController.GetCharacters(); foreach (Cost cost in costs) { cost.HidePointCost(updatedOwnedCharacters); } } PlayerPrefsController.SetCharacter(characterChoice); foreach (CharacterSelectionButton characterButton in characterButtons) { if (characterButton.CharacterIndex == characterChoice) { characterButton.GetComponent <Toggle>().interactable = false; globalManager.CharacterSprite = selectedCharacter.CharacterSprite; globalManager.CharacterRuntimeAnimatorController = selectedCharacter.CharacterRuntimeAnimatorController; globalManager.PlayerHealth = selectedCharacter.PlayerHealth; globalManager.SetCharacter(player); } else { characterButton.GetComponent <Toggle>().interactable = true; } } }
// Update is called once per frame void Update() { if (PlayerPrefsController.GetBestScore() >= 25 && PlayerPrefsController.GetPoints25() == false && Application.internetReachability != NetworkReachability.NotReachable) { Unlock25Points(); } else if (PlayerPrefsController.GetBestScore() >= 50 && PlayerPrefsController.GetPoints50() == false && Application.internetReachability != NetworkReachability.NotReachable) { Unlock50Points(); } else if (PlayerPrefsController.GetBestScore() >= 100 && PlayerPrefsController.GetPoints100() == false && Application.internetReachability != NetworkReachability.NotReachable) { Unlock100Points(); } else if (PlayerPrefsController.GetBestScore() >= 200 && PlayerPrefsController.GetPoints200() == false && Application.internetReachability != NetworkReachability.NotReachable) { Unlock200Points(); } else if (PlayerPrefsController.GetBestScore() >= 500 && PlayerPrefsController.GetPoints500() == false && Application.internetReachability != NetworkReachability.NotReachable) { Unlock500Points(); } else if (PlayerPrefsController.GetCharacters().Length >= 3 && PlayerPrefsController.GetCharacters2() == false && Application.internetReachability != NetworkReachability.NotReachable) { Unlock2Characters(); } else if (PlayerPrefsController.GetCharacters().Length >= 6 && PlayerPrefsController.GetCharacters5() == false && Application.internetReachability != NetworkReachability.NotReachable) { Unlock5Characters(); } else if (PlayerPrefsController.GetCharacters().Length >= 11 && PlayerPrefsController.GetCharacters10() == false && Application.internetReachability != NetworkReachability.NotReachable) { Unlock10Characters(); } else if (PlayerPrefsController.GetCharacters().Length >= 21 && PlayerPrefsController.GetCharacters20() == false && Application.internetReachability != NetworkReachability.NotReachable) { Unlock20Characters(); } else if (PlayerPrefsController.GetCharacters().Length >= 31 && PlayerPrefsController.GetCharacters30() == false && Application.internetReachability != NetworkReachability.NotReachable) { Unlock30Characters(); } }