private void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.CompareTag("Enemy") || other.gameObject.CompareTag("EnemyWeapon"))
{
// Debug.Log("OnCollisionEnter "+isPlaying(animator, "hero_attack_persistant"));
if (isPlaying(animator, "heroWeaponAttack") == true)
{ //|| isPlaying(animator, "hero_attack_persistant") == true
//kill enemy if attack animation is playing when colliding
// Destroy(other.gameObject);
animator.SetBool("whenHit", false);
}
else
{
bool disFroze = false;
if (other.gameObject.TryGetComponent(out HealthAndDeath had))
{
if (had.isFrozen)
{
disFroze = true;
}
}
if (!disFroze)
{
animator.SetBool("whenHit", true);
if (!Sword.activeSelf && other.gameObject.TryGetComponent(out IDamageable hds))
{
ReceiveDamage(hds.SendDamage());
}
else if (Sword.activeSelf && other.gameObject.TryGetComponent(out IDamageable ds) && other.gameObject.CompareTag("HeroWeapon"))
{
Sword heldSword = Sword.GetComponent();
ds.ReceiveDamage(heldSword.damageAmount, "sword");
}
}
//hero dead
//clearActions();
//Destroy(gameObject);
}
}
}
Leave a Reply