The situation is:
I have a melee weapon script - it consists of the Physics Overlap Sphere, in which targets will get Damage, when the Player pushes Fire button.
The problem is: I need it to Send Message just to the first two of the Targets (of more specificly: number of enemies determined by Max Targets variable).
FOR NOW:
It simply sends message to ALL Enemies in range. How should I limit it to just two enemies?
The Code:
#pragma strict
public var MeleeRange : float = 5;
public var TheDamage : float = 500;
var TargetsInRange = new Transform[2]; //<-- Number "2" is there for a placeholder.
var MaxTargets : int = 2; //<-- This should be the number of Enemies to SendMessage.
function Update ()
{
var TargetsInRange = Physics.OverlapSphere(transform.position, MeleeRange);
for each (var Target in TargetsInRange)
{
if (Input.GetButtonDown("Fire") && Target.gameObject.transform.tag == "Enemy")
{
Target.SendMessage("ApplyDamageNormal", TheDamage, SendMessageOptions.DontRequireReceiver);
}
}
}
↧