using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class InventoryBasic : MonoBehaviour
{
    private List<GameObject> items;
    // Start is called before the first frame update
    void Start()
    {
        items = new List<GameObject>();
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    
    private void OnCollisionEnter2D(Collision2D other)
    {
        switch (other.gameObject.tag) // switch-case hier damit in zukunft einfach fälle hinzugefügt werden können
        {
            case "Item":
                other.gameObject.SetActive(false);
                items.Add(other.gameObject);
                Debug.Log("Pickup: Take " + other.gameObject.name);
                break;
            
            case "Openable":
                // Entfernt den ersten "Key" welcher unter den Items gefunden wird, falls es einen gibt
                if ( items.Remove((from item in items where item.name == "Key" select item).First()) )
                {   // falls ein "Key" gefunden wurde, wird dieser genutzt
                    other.gameObject.SetActive(false);
                    Debug.Log("Pickup: Use Key");
                }
                break;
        }
    }
}