Hmm, I think I must be missing something- I tried setting up a bool to indicate whether or not I wanted the messenger to fire, and toggled it with each attack (which in turn is constrained by a cooldown timer) as follows:
void Update () {
if (attackTimer > 0)
attackTimer -= Time.deltaTime;
else
if (attackTimer < 0) {
attackTimer = 0;
canAttack = true;
}
if (Input.GetKeyDown(KeyCode.Alpha1)){
if (attackTimer==0){
attackTimer = coolDown;
Attack();
}
//gameObject.SendMessage("EvaluateAttack", transform.position);
}
}
anim.SetTrigger ("Punch");
Messenger.Broadcast ("Toggle melee listener", canAttack);
canAttack = false;
Messenger.Broadcast ("melee attack made", transform.position, transform.forward, damage);
public void ToggleListener(bool toggler){
canAttack = toggler;
}
}
RaycastHit hit;
if (Physics.Raycast (origin, direction, out hit, 25.0f) && hit.transform.tag == "Enemy" && canAttack == true) {
Debug.Log("Attack registered");
SuccesfulAttack(hit, damage);
}
And it still spams SuccessfulAttack. It seems like I'm massively over-complicating what should be a simple operation: is there any alternative to placing my event listeners in Update?
↧