コード例 #1
0
    /// <summary>
    /// Called when an item is picked up
    /// </summary>
    /// <param name="item">The item</param>
    /// <param name="itemPos">The position of the item</param>
    /// <param name="pickedUpByPlayer">True if the item was picked up by a player</param>
    void OnItemPickup(IItem item, Vector3Int itemPos, bool pickedUpByPlayer)
    {
        items.Remove(itemPos);

        if (pickedUpByPlayer)
        {
            GameStats.PlayerScore += item.PointValue;
            var score = ScoreCounter.GetComponent <Text>();
            score.text = GameStats.PlayerScore.ToString("D6");
            audioSource.PlayOneShot(ItemNoises[Random.Range(0, ItemNoises.Length)]);
        }

        bool triggerNextLevel = item.EndsLevel;


        if (item.OpensGate != null)
        {
            var gate = item.OpensGate;
            gates.Remove(gate);
            gate.Deactivate();
            mapNeedsRebuild = true;
        }

        item.Deactivate();

        if (triggerNextLevel)
        {
            if (pickedUpByPlayer)
            {
                RevealNextLevel();
            }
            else
            {
                OnGameOver(false);
            }
        }

        if (items.Count == 1 && !GameStats.ExitUnlocked)
        {
            audioSource.PlayOneShot(SirenNoise);
            GameStats.ExitUnlocked = true;
            foreach (var i in listeners)
            {
                i.ExitUnlocked();
            }
        }
    }