Wow, my enemies are pretty strong!

This is the worst type of question. (for me) It’s the worst because I actually had it down before, and because of some changes I had to make (and a lack of foresight on my part) I had to go back and lost what I had. (didn’t back up this one code, ugh)
Long story short: Player needs to be damaged by enemy. I included a damage component to the enemy AI. That script looks like this:

var target : Transform;
var moveSpeed = 10;
var rotationSpeed = 5;
var myTransform : Transform;
var minDistance = 10;
var stopHere = 0;
var follow : boolean = true;
var damage = 15;
     
function Awake()
{
myTransform = transform;
}
     
function Start()
{
     
target = GameObject.FindWithTag("Player").transform;
     
}

     
function Update () {
     
     
     if(Vector3.Distance(myTransform.position, target.position) < minDistance)
{
       animation.Play("Banshee Attack");   
       audio.PlayDelayed(2);
       Playerhealth.curHealth -= damage;
       }
       }

Now, even as a noob I can look at the and say “the player is going to get killed as soon as the enemy touches them,” because they won’t have any time to react, so they’ll just keep getting hit over and over. I tried putting in a wait routine (yield WaitForSeconds(10.0);) in after each instance of damage to the player, but keep getting an “update can’t be coroutine” error. Am wondering if someone can help me learn the proper way to implement that command into my code. Thanks, and God bless.

I don’t think i have to explain anything here, you will get it down :slight_smile: But basically there’s a Boolean which controls when you can be hit.

var canBeAttacked = true;

function Update () {
 
if(Vector3.Distance(myTransform.position, target.position) < minDistance)
{
   if(canBeAttacked){
      Attack();
   }
}
}

function Attack(){
   canBeAttacked = false; //can't be attacked

   animation.Play("Banshee Attack");
   audio.PlayDelayed(2);
   Playerhealth.curHealth -= damage;

   yield WaitForSeconds (10);
   canBeAttacked = true; //can be attcked after 10 seconds
}