Quantcast
Channel: Answers for "Raycast executing hundreds of times"
Viewing all articles
Browse latest Browse all 4

Answer by Sendatsu_Yoshimitsu

$
0
0
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 .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?

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images