using UnityEngine;
using System.Collections;
public class Enemy : MonoBehaviour {
public Transform thisObject;
public Transform target;
private NavMeshAgent navComponent;
Animator anim;
int runningStateHash = Animator.StringToHash("Base Layer.Running");
void Start()
{
target = GameObject.FindGameObjectWithTag("Player").transform;
navComponent = this.gameObject.GetComponent<NavMeshAgent>();
anim = GetComponent<Animator> ();
}
void Update()
{
float dist = Vector3.Distance(target.position, transform.position);
float move = Input.GetAxis ("Vertical");
anim.SetFloat ("Speed", move);
AnimatorStateInfo stateInfo = anim.GetCurrentAnimatorStateInfo (0);
if(target)
{
navComponent.SetDestination(target.position);
}
else
{
if(target = null)
{
target = this.gameObject.GetComponent<Transform>();
}
else
{
target = GameObject.FindGameObjectWithTag("Player").transform;
}
}
}
}
I use this code to animate the enemy that chases you, but I want it’s default animation (walking) to play instead of always running. Where would I declare this? I’ve tried quite a bit, and the last functioning code is the one you are seeing. Any suggestions welcomed, thanks