示例#1
0
        public void PurchaseCharacter()
        {
            SelectableCharacter character = m_PossibleCharacters[m_CurrentCharacterIndex];

            if (GameManager.Instance.TotalCoins >= character.Price)
            {
                GameManager.Instance.RemoveTotalCoins(character.Price);
                character.Unlock();
                SelectCharacter(m_CurrentCharacterIndex);
                ActivateCharacter();
            }
        }
示例#2
0
        private void SelectCharacter(int index)
        {
            if (m_PossibleCharacters.Length <= 0)
            {
                return;
            }

            //Disable all characters
            for (int i = 0; i < m_PossibleCharacters.Length; i++)
            {
                m_PossibleCharacters[i].gameObject.SetActive(false);
            }

            //Set new character
            m_CurrentCharacterIndex = index;

            //Update UI
            SelectableCharacter character = m_PossibleCharacters[m_CurrentCharacterIndex];

            m_CharacterNameText.text  = character.CharacterName;
            m_CharacterPriceText.text = "$: " + character.Price.ToString();
            m_PurchaseButton.onClick.RemoveAllListeners();
            if (character.IsUnlocked)
            {
                m_PurchaseButton.GetComponentInChildren <Text>().text = "SELECT";
                m_CharacterPriceText.text = "$: 0";
                m_PurchaseButton.onClick.AddListener(ActivateCharacter);
            }
            else
            {
                m_PurchaseButton.GetComponentInChildren <Text>().text = "BUY";
                m_PurchaseButton.onClick.AddListener(PurchaseCharacter);
            }

            //Enable new character
            m_PossibleCharacters[m_CurrentCharacterIndex].gameObject.SetActive(true);
        }