private void Update() { // Only update the //agent = GetComponent<NavMeshAgent>(); if (!shooting) { weaponScript.setActive(shooting); animator.SetBool("Shooting", shooting); } if (updatePath <= 0) { if (shooting) { //anim.Play("run"); weaponScript.setActive(shooting); walking = false; shooting = false; agent.speed = 0f; agent.isStopped = true; this.transform.parent.LookAt(PlayerLocation); updatePath = 4; } else if (walking && canWalk) { if (distanceToGoal < 3.0f) { turn = !turn; } agent.isStopped = false; agent.speed = movementSpeed; if (!turn) { agent.destination = goal.position; } else { agent.destination = start; } updatePath = 8; } } else { updatePath = updatePath - 1 * Time.deltaTime; } if (distanceToGoal <= 3.0f || !walking) { agent.speed = 0f; } //Checks the distance to the goal and turns the if (!turn) { distanceToGoal = Mathf.Abs(transform.position.x - goal.position.x) + Mathf.Abs(transform.position.z - goal.position.z); } else { distanceToGoal = Mathf.Abs(transform.position.x - start.x) + Mathf.Abs(transform.position.z - start.z); } animator.SetFloat("Speed", agent.speed); }