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

public class DamageOnTouch : MonoBehaviour
{
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Player")
        {
            if (PlayerData.instance.IsInvincible())
            {
                return;
            }
            EventBus.Publish<DamageEvent>(new DamageEvent(-1));
        }
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "Player")
        {
            // don't allow invincibility to save from losing health by falling
            EventBus.Publish<DamageEvent>(new DamageEvent(-1));
        }
    }
}

public class DamageEvent
{
    public int damage_amt = -1;
    public DamageEvent(int _damage_amt) { damage_amt = _damage_amt; }
}