Enemy Waypoint Patrol and Chase Script

using UnityEngine;
using System.Collections;

public class Enemy : MonoBehaviour {

  public GameObject[] wayPoints;
  public float patrolSpeed;
  public float chaseSpeed;
  public bool isAlert;

  private GameObject target;
  private Vector3 moveDirection;
  private int currentWaypoint;

  // Use this for initialization
  void Start () {
    isAlert = false;
    target = GameObject.FindGameObjectWithTag("Player");
    currentWaypoint = 0;
  }
  
  // Update is called once per frame
  void Update () {
    if(isAlert) {
      ChasePlayer();
    } else {
      Patrol();
    }

  }

  void Patrol () {
    isAlert = false;
    if(currentWaypoint < wayPoints.Length) {
      Vector3 dir = transform.position - wayPoints[currentWaypoint].transform.position;
      Quaternion newRotation = Quaternion.Euler(new Vector3(0, 0, Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg) );
      transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * 8);
      Debug.Log(dir.magnitude);
      if(dir.magnitude < 1) {
        currentWaypoint++;
      } else {
        dir.Normalize();
        rigidbody.velocity = dir * -patrolSpeed * Time.deltaTime;
      }
    } else {
      currentWaypoint = 0;
    }
  }

  void ChasePlayer () {
    isAlert = true;
    Vector3 dir = transform.position - target.transform.position;
    Quaternion newRotation = Quaternion.Euler(new Vector3(0, 0, Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg) );
    transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * 8);
    dir.Normalize();
    rigidbody.velocity = dir * -chaseSpeed * Time.deltaTime;

  }
}