// Update is called once per frame void Update() { combatUI.SetActive(isInCombat); float speedMagnitude; if (Input.GetKeyDown(KeyCode.Q)) { unlockEnemy(); } if (isBlocking) { animator.SetLayerWeight(1, Mathf.Lerp(animator.GetLayerWeight(1), 1, Time.deltaTime * 5)); defenseCoolDownTimer += Time.deltaTime; if (defenseCoolDownTimer >= defenseCoolDown) { defenseCoolDownTimer = 0; isBlocking = false; } } else { animator.SetLayerWeight(1, Mathf.Lerp(animator.GetLayerWeight(1), 0, Time.deltaTime * 5)); } if (!isInCombat) { isInCombat = currentEnemy != null && Vector3.Distance(transform.position, currentEnemy.transform.position) < 5f; enableAgent(true); speedMagnitude = nav.desiredVelocity.normalized.magnitude; if (Input.GetMouseButtonDown(0)) { sendOrder(); } switch (currentState) { case states.goToPosition: goToPosition(); break; case states.attackEnemy: if (currentEnemy) { attackEnemy(); } break; } } else { enableAgent(false); float h = input.Horizontal(); float v = input.Vertical(); speedMagnitude = Mathf.Abs(h + v); animator.SetFloat("vertical", v); animator.SetFloat("horizontal", h); if (speedMagnitude > 0) { faceToPosition(currentEnemy.transform.position); } if (!isInAnimatorState(0, "Attack") && !isBlocking) { if (Input.GetKeyDown(KeyCode.RightArrow) || input.SwipeX() > 0) { animator.SetTrigger("attack"); } if (Input.GetKeyDown(KeyCode.LeftArrow) || input.SwipeX() < 0) { isBlocking = true; } } } animator.SetFloat("speedMagnitude", speedMagnitude); animator.SetBool("inCombat", isInCombat); }