Here is the code I made for the enemy's attack. This function is called by another script (in C#) using SendMessage("Attack");
I tried using yield WaitForSeconds, but it only lags the first attack, then the next few are consecutive. What should I do?
asked Nov 03 '10 at 08:01 AM
I guess the problem is that you are calling Attack in rapid succession. So the effect you'd see is that the first call gets delayed and all others get called immediately after the first one.
What you need to do is using Attack as a Coroutine with a while loop inside. So you could transform your code into something like this (this should only give you an idea, it will not work as is):
Be aware that you have to call this routine only ONCE to start attacking. It will then continue to attack the target until it's out of range. So probably you'll also need a check if target died.
answered Nov 03 '10 at 08:30 AM
An alternate solution would be to 'deactivate' function 'Attack()' by setting a state in the beginning and end.
If I'm not mistaken, attacking would only be set to false only after attacklag seconds has passed.
answered Nov 03 '10 at 08:46 AM