void OnTriggerEnter2D(Collider2D hitInfo) { // Put proper hit detection code here if (hitInfo.transform.parent) { Rodent unknownRodent = hitInfo.transform.parent.gameObject.GetComponent <Rodent>(); PlayerStats king = hitInfo.transform.parent.gameObject.GetComponent <PlayerStats>(); BuildableObject unknownBuilding = hitInfo.transform.parent.gameObject.GetComponent <BuildableObject>(); if (unknownRodent) { if (unknownRodent.getTeam() == enemyTeam) { unknownRodent.Damage(attackDamage); Destroy(gameObject); } } else if (unknownBuilding) { if (unknownBuilding.getTeam() == enemyTeam && unknownBuilding.getType() != BuildableObject.BuildingType.TownCenter && unknownBuilding.getType() != BuildableObject.BuildingType.WoodPile && unknownBuilding.getType() != BuildableObject.BuildingType.StonePile && unknownBuilding.getType() != BuildableObject.BuildingType.GarbageCan) { unknownBuilding.Damage(attackDamage); Destroy(gameObject); } } else if (king) { if (enemyTeam == 1) { king.Damage(attackDamage); Destroy(gameObject); } } } }
// Handles the rat attacking an enemy IEnumerator Attack() { // Play animation //Debug.Log("Attack!Rat@" + Time.time); if (canAttack) { canAttack = false; if (anims) { // Put attack animation here anims.SetTrigger(ATK_ANIMATION_TRIGGER); } // For rodents Rodent _EnemyRodent = currentTarget.GetComponent <Rodent>(); PlayerStats king = currentTarget.GetComponent <PlayerStats>(); if (_EnemyRodent) { if (!_EnemyRodent.isDead()) {// Reduce enemy health _EnemyRodent.Damage(attackDamage); SoundManager.Instance.PlayCombat(); } else { _inRange.Remove(currentTarget); // print("Called from Dead Rodent found"); FindNextTargetInRange(); } } else if (king) { if (!king.isDead()) { king.Damage(attackDamage); SoundManager.Instance.PlayCombat(); } else { _inRange.Remove(currentTarget); FindNextTargetInRange(); } } else { BuildableObject _enemyBuilding = currentTarget.GetComponent <BuildableObject>(); if (_enemyBuilding.getHP() > 0 && _enemyBuilding.getType() != BuildableObject.BuildingType.TownCenter) { _enemyBuilding.Damage(attackDamage); SoundManager.Instance.PlayCombat(); } else { _inRange.Remove(currentTarget); // print("Called from Dead Building found"); FindNextTargetInRange(); } } yield return(new WaitForSeconds(1.16f)); //Length of attack animation canAttack = true; } }