Need help fast!!!

I’m making a short game for a school project. I am making a scene where you are Perseus and you are fighting medusa. How do i make a symple AI Script so when my guy is so close to medusa, she attacks every lets say 2 seconds? BUT ONLY when he is close enough.??

You can have a look at the FPS tutorial posted here: http://unity3d.com/support/resources/tutorials/fps-tutorial-part1
The third part of the tutorial has the AI feature. You should download the entire tutorial and look at how the enemies work. I hope this helps.

I did, but for that, the AI shoots at your from a distance. I want it so when they are close to you, they attack. Prob something like this.

var attc : int =5;

function Update(){
if (attc <= 5)
SOME CODE HERE TO ATTACK
}

but how would i get the distance/ attack code?

Add a large sphere collider around medusa and set its “isTrigger” so when Perseus goes into it, an OnTriggerEnter() function can launch the attack code.

You can use the Vector3.Distance function : Unity - Scripting API: Vector3.Distance

For eg:

var perseus: Transform;
function Update() {
var dist = Vector3.Distance(perseus.position, transform.position);
print ("Distance to other: " + dist);
if(dist < = 5)
{
//Fire in the hole
}
}

You can attach this script to medusa.