// Update is called once per frame void Update() { //Checking to see if player is close by float dist = Vector2.Distance(player.transform.position, transform.position); if (dist < 0) { dist = dist * -1; } if (dist <= 6 && waitTime <= 0) { if (dist <= 0.75) { state = 2; waitTime = 3f; } state = 1; } else { if (currentNode.getPosition().x == p.getCurrrentNode().getPosition().x&& currentNode.getPosition().y == p.getCurrrentNode().getPosition().y) { state = 0; } else { state = 2; } } if (state == 1) { //Chasing player p.SetActive(0); fp.SetActive(1, currentNode); rp.SetActive(0, null); } else if (state == 2) { //Go back to the patrol route p.SetActive(0); fp.SetActive(0, null); rp.SetActive(1, currentNode); } else if (state == 0) { //Go on patrol p.SetActive(1); fp.SetActive(0, null); rp.SetActive(0, null); } if (waitTime <= 0) { waitTime = 0; } else { waitTime -= Time.deltaTime; } }