Enemy AI Script

I opened a question on this about a week ago and had a reply however the script i was given i can't seem to get it to work without constantly getting errors telling me to add ';' in different places which then results in more errors.

I have a script i had taken from the FPS Tutorial that allows my enemy to move to waypoints, spot my character within range and then start attacking. (the script is rather long so wasn't sure if i should post it)

However i want the enemy to use a variety of attacks at random, for example he might either use attack 1 (normal swipe) attack 2 (tail swipe) or attack 3 (special move).

Here is the script that i have from my last question:

var WaitTime:int=10; // betweenattacks

function monsterAttack(){

while (true){

var distance:Vector3=(Player1.transform.position-Enemy.transform.position);

var dis:float=distance.magnitude;

if (dis<100) do_attack(1) else do_attack(2);

yield WaitForSeconds(WaitTime);

if (dis<100) do_attack(2) else do_attack(3);

yield WaitForSeconds(WaitTime);

if (dis<100) do_attack(3) else do_attack(1);

yield WaitForSeconds(WaitTime);

}

}

Any help would be great. Thank you!

EDIT: Fixed it myself, after gaining more scripting knowledge i realised that i was being a fool and needed to add the animations into the 'do_attack' part and it works fine.

Fixed it myself:

var distance:Vector3=(player.transform.position-enemy.transform.position); var dis:float=distance.magnitude;

if (hp.health<500) animation.CrossFade("normalattack", 0.3); else animation.CrossFade("secondaryattack", 0.3);

yield WaitForSeconds(delayShootTime); targetGameObject.active = false;

if (hp.health<300) animation.CrossFade("secondaryattack", 0.3); else animation.CrossFade("normalattack", 0.3);

yield WaitForSeconds(delayShootTime); targetGameObject.active = false;

if (hp.health<100 ) yield StartCoroutine("Special");

yield WaitForSeconds(delayShootTime); targetGameObject.active = false; }

function Special () { fire.active = true;

var distance:Vector3=(player.transform.position-enemy.transform.position); var dis:float=distance.magnitude;

if (hp.health<100 ) animation.CrossFade("specialattack", 0.3); else animation.CrossFade("specialattack", 0.3); audio.Play(); }

I need that script can you please post it

Hi jack,

i’m also having same requirement to my game i.e., an AI enemy script. that enemy wants to attack on a gameobject with different actions.

can u please post the script and explain the same?

thanks in advance…

im new and do any of these scripts work for enemys??