Hi I am trying to get an enemy to play 2 animations
the first when he is not moving and the second when he runs at the player. currently the enemy will play the idle animation but only play about 2 frames of the run animation.
Any assistance on this would be greatly appreciated
var distance;
var target : Transform;
var lookAtDistance = 10.0;
var attackRange = 6.0;
var moveSpeed = 5.0;
var damping = 6.0;
animation["idle"].layer = -1;
animation["run"].layer = 1;
function Update ()
{
distance = Vector3.Distance(target.position, transform.position);
animation.Play("idle", PlayMode.StopAll);
if(distance < lookAtDistance)
{
isItAttacking = false;
renderer.material.color = Color.yellow;
lookAt ();
}
if(distance > lookAtDistance)
{
renderer.material.color = Color.green;
}
if(distance < attackRange)
{
attack ();
}
if(isItAttacking)
{
renderer.material.color = Color.red;
}
}
function lookAt ()
{
var rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
}
function attack ()
{
isItAttacking = true;
renderer.material.color = Color.red;
transform.Translate(Vector3.forward * moveSpeed *Time.deltaTime);
animation.Play("run", PlayMode.StopAll);
}