I am following a tutorial and have written the following code to make my zombie walk in the game. He will move in olace (idke) but not move forward on the nav mesh?
Thanks
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class ZombieAI : MonoBehaviour
{
NavMeshAgent agent;
Transform target;
Animator anim;
// Use this for initialization
void Start ()
{
target = GameObject.FindGameObjectWithTag("Player").transform;
agent = GetComponent<NavMeshAgent> ();
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update ()
{
float distance = Vector3.Distance (transform.position, transform.position);
if (distance > 1.5)
{
agent.updatePosition = true;
agent.SetDestination(target.position);
anim.SetBool ("isWalking", true);
anim.SetBool ("isAttacking", false);
}
else
{
agent.updatePosition = false;
anim.SetBool ("isWalking", false);
anim.SetBool ("isAttacking", true);
}
}
}
Thanks.
