// Update is called once per frame void Update() { if (positioned == 20) { transform.position = startingPosition; } positioned++; switch (isCurrently) { case guardState.patrolling: { if (DoISeePlayer()) { Debug.Log("I See Player"); Shooting(); } if (transform.position == agent.destination) { nextPoint.SetActive(true); Searching(); } } break; case guardState.searching: { if (DoISeePlayer()) { Debug.Log("I See Player"); Shooting(); } transform.Rotate(Vector3.up, turningSpeed * Time.deltaTime * turningDirection); //direction indicates on which side he turns if (totalSearchTimer > nextTurnTime) { turningDirection *= -1; nextTurnTime = GetNextTurnTime(nextTurnTime); } totalSearchTimer += Time.deltaTime; if (totalSearchTimer > searchTime) { Patrolling(); } } break; case guardState.shooting: { Vector3 dirToPlayer = (myManager.GetPlayerPosition() - transform.position).normalized; transform.forward = new Vector3(dirToPlayer.x, 0, dirToPlayer.z); if (DoISeePlayer()) { totalDrawTimer += Time.deltaTime; if (totalDrawTimer > timeToDraw) { Shoot(); } } else { agent.isStopped = false; isCurrently = guardState.patrolling; guardAnimator.SetBool("isIdling", false); guardAnimator.SetBool("isWalking", true); guardAnimator.SetBool("isShooting", false); } } break; } }