private void Explode() { Collider[] hitColliders = Physics.OverlapSphere(transform.position, radius); if (hitColliders.Length > 0) { foreach (Collider inRangeUnit in hitColliders) { if (inRangeUnit.transform.tag == "Mob") { MobController enemy = inRangeUnit.gameObject.GetComponent <MobController>(); if (enemy != null && friendly != enemy.friendly) { if (Random.Range(0f, 1f) > enemy.dodgeChance) { enemy.Project(((enemy.transform.position + Vector3.up * 10f) - transform.position).normalized * projectionPower); enemy.TakeDamage(caster.GetComponent <MobController>().CalcDamage(enemy.armor), true); } else { enemy.Dodge(); } } } } } }
// added random pre-attack delay after demo so mobs don't all attack at once private void Attack(GameObject target, float t) { MobController enemy = target.GetComponent <MobController>(); LookAt(target.transform.position, t); if (attackTimer <= 0) { preAttackDelay = Random.Range(0f, preAttackMaxDelay); if (preAttackTimer <= 0) { animation.Play("attack"); attackTimer += attackDelay; preAttackTimer += preAttackDelay; if (gameObject.name.Equals("skeletonMage(Clone)")) { GameObject fireball = (GameObject)Instantiate(fireballPrefab, transform.position + (transform.forward + transform.up) / 2f, Quaternion.identity); fireball.GetComponent <FireballScript>().Init(gameObject, enemy.transform.position, friendly); } else { if (Random.Range(0f, 1f) > enemy.dodgeChance) { enemy.TakeDamage(CalcDamage(enemy.armor), false); } else { enemy.Dodge(); } } } preAttackTimer -= t; } attackTimer -= t; }