public void ActivateCharacter(int index)
 {
     // Player is unlocked
     activeChar = allCharButtons[index];
     Debug.Log(index);
     if (PlayerPrefs.GetInt("char" + activeChar.CharacterText.text) == 1)
     {
         //TODO: Activate character
         Debug.Log("Selecting: " + activeChar.CharacterText.text);
         PlayerPrefs.SetInt("selectedChar", index);
         CharacterMenuPanel.SetActive(false);
     }
     else
     {
         // If not enough schrute bucks, display message
         Debug.Log("Char " + activeChar.CharacterText.text + " costs " + activeChar.CostText.text);
         Debug.Log("You have " + PlayerPrefs.GetInt("schruteBucks").ToString());
         if (Int32.Parse(activeChar.CostText.text) > PlayerPrefs.GetInt("schruteBucks"))
         {
             // display not enough schrute bucks panel
             InvalidPurchasePanel.SetActive(true);
             // Reset active char
             activeChar = null;
         }
         else
         {
             // display confirmation purchase panel
             ConfirmationPurchasePanel.SetActive(true);
         }
     }
 }
    void FillList()
    {
        int i = 0;

        foreach (var character in CharacterList)
        {
            GameObject newButton = Instantiate(buttonPrefab) as GameObject;
            newButton.transform.SetParent(Spacer);

            // Get C# script on button
            CharacterMenuButton charButton = newButton.GetComponent <CharacterMenuButton>();
            charButton.CharacterText.text = character.Name;
            // Add character name to array for reference in button listeners
            charNameArray.Add(character.Name);

            // Check if character is unlocked
            if (PlayerPrefs.GetInt("char" + charButton.CharacterText.text) == 1)
            {
                character.Unlocked = 1;
                // Set white character outline if unlocked
                charButton.CharImageOutline.sprite = character.CharImageOutline;
            }
            else
            {
                // Set grey overlay over character if its locked
                charButton.CharImage.color        = new Color32(60, 60, 60, 100);
                charButton.CharacterText.color    = new Color32(255, 255, 255, 70);
                charButton.CharImageOutline.color = new Color32(255, 255, 255, 0);
            }
            // // Store its index in the c
            // PlayerPrefs.SetInt("char_index" + charButton.CharacterText.text, i);
            // Set new button's character name to input character name, cost, and image
            charButton.unlocked             = character.Unlocked;
            charButton.CharImage.sprite     = character.CharImage;
            charButton.CostText.text        = character.Cost;
            charButton.CostTextOutline.text = character.Cost;

            charButton.GetComponent <Button>().interactable = true;
            // Add button click listener
            // Some weird binding issue here, so initialize a new var as a workaround
            int j = i;
            Debug.Log(j);
            Debug.Log(charButton.CharacterText.text);
            charButton.GetComponent <Button>().onClick.AddListener(() => ActivateCharacter(j));
            allCharButtons.Add(charButton);
            i++;
        }
        // Save characters
        SaveAll();
    }
    void PurchaseCharacter()
    {
        // Only make a purchase if a character has been selected
        Debug.Log("char to purchase: " + activeChar.CharacterText.text);
        if (activeChar != null)
        {
            int schruteBucks = PlayerPrefs.GetInt("schruteBucks");
            int cost         = Int32.Parse(activeChar.CostText.text);
            PlayerPrefs.SetInt("schruteBucks", schruteBucks - cost);
            activeChar.unlocked   = 1;
            SchruteBucksText.text = PlayerPrefs.GetInt("schruteBucks").ToString();

            ConfirmationPurchasePanel.SetActive(false);
            // Save unlocked character
            PlayerPrefs.SetInt("char" + activeChar.CharacterText.text, 1);
            // Remove grey overlay
            activeChar.CharImage.color        = new Color32(255, 255, 255, 255);
            activeChar.CharacterText.color    = new Color32(255, 255, 255, 255);
            activeChar.CharImageOutline.color = new Color32(255, 255, 255, 255);
            // Reset active char
            activeChar = null;
        }
    }