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

public class Junk : MonoBehaviour
{
    [SerializeField] int Reward = 20;
    [SerializeField] LayerMask PlayerMask;
    [SerializeField] AudioClip SFXPickUp;
    [SerializeField] Animator Animator;

    public static System.Action OnPickedUp;

    private void OnCollisionEnter(Collision collision)
    {
        if (PlayerMask != (PlayerMask | (1 << collision.gameObject.layer))) return;
        
        PickUpJunk();
        OnPickedUp();
    }

    private void PickUpJunk()
    {
        PlayerData player = FindObjectOfType<PlayerData>();
        player.Money += Reward;
        if (SFXPickUp != null)
            AudioSource.PlayClipAtPoint(SFXPickUp, transform.position);
        Animator?.SetTrigger("Pickup");
        Debug.Log("Pickup");
    }

    public void OnAnimationEnd()
    {
        Debug.Log("Destroy");
        Destroy(gameObject);
    }
}
