- Home /
Error with NavMeshAgent.get_velocity ()
I am using velocity of NavMeshAgent to control the animations of the enemy.
void Update () {
if (AI.velocity.x > 0 && state !=2) { direction = 2; state = 2;
anima.Play ("Walk_Right"); } if (AI.velocity.x < 0 && state != 1) { direction = 1; state = 1; anima.Play ("Walk_Left"); } if (AI.velocity.x == 0 && state != 0) { state = 0; if (direction == 1) {
anima.Play ("Idle_Left"); } else {
anima.Play ("Idle_Right");} } }
Sometimes it works, but sometimes I get an error: NullReferenceException UnityEngine.NavMeshAgent.get_velocity() What could it mean?
Comment