using Assets.Scripts.Enums;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Pickup : MonoBehaviour
{
    public Item item;

    public Vector3 spinRotatationSpeed = new Vector3(0, 180, 0);

    public SoundName soundName;


    private void OnCollisionEnter2D(Collision2D collision)
    {
        Collider2D collider = collision.collider;
        // get <Inventory> object if collision object has it
        Inventory inventory = collider.GetComponent<Inventory>();
        Debug.Log("Pickup collected by: " + collision.gameObject);
        Debug.Log("Inventory: " + inventory);
        // OnTrigger with <Inventory>
        if (inventory)
        {
            // Pickup health if not at max HP
            if (inventory.AddItem(item))
            {
                SoundManager.instance.PlaySoundAtPoint(gameObject, soundName);
                Destroy(gameObject);
            }
        }
    }

    //private void OnTriggerStay2D(Collider2D collision)
    //{
    //    // pickup while inside collision
    //    OnCollisionEnter2D(collision);
    //}

    private void Update()
    {
        // rotate pickup object
        transform.eulerAngles += spinRotatationSpeed * Time.deltaTime;
    }
}