protected override void enemyInteraction(Mob enemy) { setTarget(enemy); if (enemy.target == null) { enemy.setTarget(this); } }
// Gunmen will heal hurt allies that do not have a target protected override void allyInteraction(Mob ally) { // The ally is roaming and has no target if (ally.target == null) { // Heal the ally if injured if (ally.CurrentHealth < ally.MaxHealth) { setTarget(ally); ally.setTarget(this); } // Turn away from the ally if it is at full health else { // Get the ally's direction Vector2 rayDirection = ally.transform.position - transform.position; // Check to see if the ally is within the field of view if (Vector2.Angle(rayDirection, transform.up) <= fieldOfView / 2) { // Fire a ray towards the ally RaycastHit2D hit = Physics2D.Raycast(transform.position, rayDirection, visionRange); // Turn away from the ally if there is a collision if (hit != null && hit.collider != null) { transform.up = hit.normal; float turn = Random.Range(-rotationRange, rotationRange); transform.Rotate(0f, 0f, turn); } } } } // Help the ally that is fighting an enemy else { // Checks how far the enemy is from this mob to prevent allies // from chain detecting a mob from across the map if (Vector2.Distance(transform.position, ally.target.transform.position) <= visionRange * 2 && ally.target.tag != tag) { setTarget(ally.target); } } }
protected override void enemyInteraction(Mob enemy) { // Set this mob's target to be the detected enemy setTarget(enemy); // Prevents the enemy from wandering aimlessly while being shot if (enemy.target == null) { enemy.setTarget(this); } }