To me more specific, I'm trying to have a timer that starts when the player starts attacking, to measure the amount of time passed since they last press the button. If they don't press the attack button again within a certain window, the player goes back to idle. However, I'm having trouble getting my code to detect when the button is being pressed in another method aside from the one using Context.Started. For whatever reason, I don't think the Input.GetKeyDown is working. atkTimer is the initial timer for measuring the time between button presses, and atkCancel is meant to cancel the attack if the player doesn't hit the button fast enough. Here's the relevant code:

public bool isSlashing = false; private float atkCountdown = 0f; private float atkCount; public void Slash(InputAction.CallbackContext context) { if (context.started && !isSlashing && atkCountdown == 0f) { isSlashing = true; Debug.Log("slash!"); PlayerAnimator.SetBool("Slashing", true); PlayerAnimator.SetFloat("SlashCount", 1); StartCoroutine(atkTimer()); StartCoroutine(atkCancel()); } } public IEnumerator atkTimer() { yield return new WaitForSeconds(0.1f); //isSlashing = false; if (Input.GetKeyDown(KeyCode.J) && atkCountdown <= 1f) { //if (Slash().InputAction.context.started == true) //{ //} //I know the above code doesn't work, but I needed to give you an idea of what I'm trying to do. atkCount++; PlayerAnimator.SetFloat("SlashCount", atkCount); atkCountdown = 0f; Debug.Log(atkCount); Debug.Log(PlayerAnimator.GetFloat("SlashCount")); if (atkCount <= 6) { } } Debug.Log("Testing!"); } public IEnumerator atkCancel() { if (atkCountdown >= 1f) { isSlashing = false; atkCountdown = 0f; Debug.Log("Cancel time!"); PlayerAnimator.SetBool("Slashing", false); PlayerAnimator.SetFloat("SlashCount", 0); StopCoroutine(atkTimer()); //PlayerAnimator.SetFloat("TransCount", atkCount); //isSlashing = false; //atkCountdown = 0f; //atkCount = 0f; } yield return null; }

Herobrine Yoko's user avatar

4

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.