/// <summary> /// Explodes the chicken, and damages all enemies in the specified radius. /// </summary> protected void PerformExplosionProcedure() { Transform[] enemies = GetAllEnemiesInRange(attackRadius); foreach (Transform enemy in enemies) { if (enemy.GetComponent <MonoBehaviour>() is BaseEnemy) { BaseEnemy e = (enemy.GetComponent <MonoBehaviour>() as BaseEnemy); if (e != null) { try { // Deal damage to the enemy e.TakeDamage(damage, this, transform.position, true); } catch (Exception ex) { Debug.Log("[ChickenBehaviour]: Error! Chicken behaviour had problems to damage enemy.\n" + ex.ToString()); } } } } // Calculate new target if enemy does not die. foreach (Transform enemy in influencedEnemies) { if (enemy != null && enemy.GetComponent <MonoBehaviour>() is BaseEnemy) { BaseEnemy e = (enemy.GetComponent <MonoBehaviour>() as BaseEnemy); if (e.Health > 0) { e.CalculateTargetPlayer(); } } } // Explosion if (explosionParticle != null) { Instantiate(explosionParticle, transform.position, explosionParticle.transform.rotation); } // Sound if (explosionSound != null) { SoundManager.SoundManagerInstance.Play(explosionSound, transform.position, AudioGroup.Effects); } // Camera shake CameraManager.CameraReference.ShakeOnce(); Destroy(this.gameObject); }
public override void Reason(GameObject player, GameObject npc) { MonoBehaviour m = npc.GetComponent <MonoBehaviour>(); if (m is BaseEnemy) { BaseEnemy e = (BaseEnemy)m; if (e.TargetPlayer != null) { e.SetTransition(Transition.SawPlayer); } if (currentRecalculationTime >= recalculateTargetTime) { e.CalculateTargetPlayer(); currentRecalculationTime = 0f; } currentRecalculationTime += Time.deltaTime; } }