- Home /
How to animate a enemy when he is following
i want to the enemy(Zombie) plays an animation when following the player, i already have something but it doesnt work using UnityEngine; using System.Collections;
[RequireComponent (typeof (CharacterController))]
public class BehaviorZombie : MonoBehaviour {
//Component
public Transform target;
//Movement
public float moveSpeed = 5;
//States
private int range = 5;
private int state = 0;
void Start () {
target = GameObject.FindGameObjectWithTag("Player").transform;
animation.Play("Idle", PlayMode.StopAll);
}
void Update () {
if (Vector3.Distance(transform.position, target.position) < range){
IdleState();
}
if (Vector3.Distance(transform.position, target.position) < range){
AlertState();
}
}
private void IdleState () {
}
private void AlertState () {
Debug.Log("following");
transform.LookAt(target);
transform.Translate(Vector3.forward * Time.deltaTime * moveSpeed);
animation.Play("Walk_Zombie", PlayMode.StopAll);
}
}
i want them to blend between an idle animation, and a walk animation...
thanks for your time excuse my english
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613135643im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can the animation editor create local rotational data? 3 Answers
How to animate Enemy 1 Answer
Adding animation clips via script 2 Answers
How to make zombie head burst effect? 1 Answer
Make the Enemy animation stops 0 Answers