private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Player") { HealthComp PlayerHealthComponent = collision.gameObject.GetComponent <HealthComp>(); if (PlayerHealthComponent) { PlayerHealthComponent.OnHit(Damage); } } }
private void OnTriggerStay2D(Collider2D collision) { if (collision.gameObject.tag == "Enemy") { HealthComp EnemyHealthComponent = collision.gameObject.GetComponent <HealthComp>(); if (EnemyHealthComponent && bCanAttack) { bCanAttack = false; EnemyHealthComponent.OnHit(1); Debug.Log("End Health Enemy: " + EnemyHealthComponent.GetCurrentHealth()); } } }