void OnTriggerStay2D(Collider2D other) { if (paused) { return; } if (colliderIsHero(other) && this.isDying == false) { MovableHeroScript moveableHero = other.GetComponent <MovableHeroScript> (); if (moveableHero != null && moveableHero.isDragging) { return; } else { isTouchingHero(other); } HeroScript heroCharacter = other.GetComponent <HeroScript> (); attackTimer -= Time.deltaTime / currentAttackSpeed; if (attackTimer <= 0.0f && heroIsInFront(other)) { attackTimer = defaultAttackSpeed; attackSound.Play(); bool didKillhero = heroCharacter.takeDamage(attackPower); if (didKillhero) { stoppedTouchingHero(other); } } } }
// collisions void OnTriggerEnter2D(Collider2D other) { if (colliderIsBullet(other)) { BulletScript bulletScript = other.gameObject.GetComponent <BulletScript> (); int damageToTake = bulletScript.damage; switch (bulletScript.bulletType) { case BulletType.BASIC: if (enemyType == EnemyType.FAST_STRONG || enemyType == EnemyType.STRONG) { damageToTake /= 2; } break; case BulletType.ICE: if (enemyType != EnemyType.ICE_RESISTANT) { freeze(); } if (enemyType == EnemyType.FAST_STRONG || enemyType == EnemyType.STRONG) { damageToTake /= 2; } break; case BulletType.HEAVY_ICE: if (enemyType != EnemyType.ICE_RESISTANT) { freeze(); } break; default: break; } switch (this.enemyType) { case EnemyType.BASIC: case EnemyType.STRONG: case EnemyType.ICE_RESISTANT: pierceSound.Play(); break; case EnemyType.FAST: case EnemyType.FAST_STRONG: hitSound.Play(); break; default: break; } takeDamage(damageToTake); } else if (colliderIsHero(other)) { if (paused) { return; } MovableHeroScript moveableHero = other.GetComponent <MovableHeroScript> (); if (moveableHero != null && moveableHero.isDragging) { return; } else { isTouchingHero(other); } } }