Esempio n. 1
0
    /// <summary>
    /// Tries to add an item to the LevelInventory. Nothing happens if Inventory is already full.
    /// </summary>
    /// <param name="power">The powerup type to add to the inventory.</param>
    public void AddPowerupToUI(Powerup.Power power)
    {
        for (int i = 0; i < pwrInventory.Length; i++)
        {
            if (pwrInventory [i] == Powerup.Power.none)
            {
                pwrInventory [i] = power;
                OnInventoryChange();
                return;
            }
        }

        Debug.Log("Inventory is already full!");
    }
Esempio n. 2
0
    /// <summary>
    /// Returns the amount of a particular powerup.
    /// </summary>
    public int GetPowerupAmount(Powerup.Power ptype)
    {
        string powerupName = ptype.ToString();

        if (PlayerPrefs.HasKey(powerupName))
        {
            return(PlayerPrefs.GetInt(powerupName, 0));
        }
        else
        {
            Debug.LogWarning("Powerup type: " + powerupName + " does not exist in the PlayerPrefs");
            PlayerPrefs.SetInt(powerupName, 0);
        }

        return(0);
    }
Esempio n. 3
0
    /// <summary>
    /// Collect a powerup (anywhere in-game) and add it to the GlobalInventory (and LevelInventory).
    /// </summary>
    public void CollectPowerup(Powerup.Power ptype)
    {
        // Pass the powerup to the level inventory.
        LevelInventory.Instance.AddPowerupToUI(ptype);

        string powerupName = ptype.ToString();

        if (PlayerPrefs.HasKey(powerupName))
        {
            int powerupCount = PlayerPrefs.GetInt(powerupName);
            PlayerPrefs.SetInt(powerupName, powerupCount + 1);
        }
        else
        {
            PlayerPrefs.SetInt(powerupName, 1);
        }

        // Only save collecting powerups after finishing level??
        PlayerPrefs.Save();
    }
Esempio n. 4
0
    /// <summary>
    /// Spend a powerup from the GlobalInventory. (Called when user clicks a powerup slot).
    /// </summary>
    /// <param name="ptype"></param>
    public void SpendPowerup(Powerup.Power ptype)
    {
        string powerupName = ptype.ToString();

        if (PlayerPrefs.HasKey(powerupName))
        {
            int powerupCount = PlayerPrefs.GetInt(powerupName);
            if (powerupCount < 1)
            {
                Debug.LogError("Trying to spend " + powerupName + " powerup, but the user doesn't have any!");
            }
            else
            {
                PlayerPrefs.SetInt(powerupName, powerupCount - 1);
            }
        }
        else
        {
            Debug.LogError("Trying to spend " + powerupName + " powerup, but it doesn't exist in PlayerPrefs!");
        }

        // Do we want to allow retry with all three powerups if one was already spent??
        PlayerPrefs.Save();
    }