using UnityEngine;

public class PlayerLogic : MonoBehaviour
{
    [SerializeField] private Transform groundCheck;
    [SerializeField] private LayerMask ShipPartsLayer;
    [SerializeField] private LayerMask DestroiedShipPartsLayer;
    [SerializeField] private GameObject DemonHead;
    public float instanity = 0;

    public bool instane;

    public float getSanityStatus()
    { return 100 - instanity; }

    public void addToInsanity(float x)
    {
        instanity += x;
        if (instanity > 100) instane = true;
    }


    public void Smash()
    {
        Collider2D ShipPartUnderFeet = Physics2D.OverlapCircle(groundCheck.position, 0.1f, ShipPartsLayer);

        if (ShipPartUnderFeet)
        {
            RaycastHit2D isDemonVisible = Physics2D.Raycast(
                ShipPartUnderFeet.gameObject.transform.position,
                DemonHead.GetComponent<Transform>().position,
                30);

            if (isDemonVisible != null && isDemonVisible.collider != null)
            {
                Debug.Log(ShipPartUnderFeet.gameObject.name);
                ShipPartUnderFeet.gameObject.GetComponent<ShipPartLogic>().TakeDamage(DemonHead, gameObject, DestroiedShipPartsLayer);
            }
        }
    }

}
