Hi!! I have a enemy ai script and it works fine. But when I tried to add the animation code to it, the only animation it plays is the RUN animation. When the scene starts he’s just in T-Pose but when he starts following me he plays the RUN animation and it doesn’t stop.
Here’s my script (commented portion is what I put in)
#pragma strict
var target : Transform; //the enemy's target
var moveSpeed = 3; //move speed
var rotationSpeed = 3; //speed of turning
var range : float = 10f;
var range2 : float = 10f;
var stop : float = 6f;;
var myTransform : Transform; //current transform data of this enemy
//public var Idle : AnimationClip; **MY INPUT**
//public var Run : AnimationClip; **MY INPUT**
//public var Attack : AnimationClip; **MY INPUT**
//public var Die : AnimationClip; **MY INPUT**
function Awake()
{
myTransform = transform; //cache transform data for easy access/preformance
}
function Start()
{
target = GameObject.FindWithTag("Player").transform; //target the player
}
function Update () {
//rotate to look at the player
var distance = Vector3.Distance(myTransform.position, target.position);
if (distance<=range2 && distance>=range){
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
}
else if(distance<=range && distance>stop){
//move towards the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
/*if(moveSpeed < 3) **MY INPUT**
{
animation.CrossFade(Idle.name); **MY INPUT**
}
if(moveSpeed > 3) **MY INPUT**
{
animation.CrossFade(Run.name); **MY INPUT**
}*/
else if (distance<=stop) {
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
}
}
I did the best to my knowledge. PLEASE HELP!!! Thx!!