Pac0의 대답이 시나리오에 대한 올바른 "키를 여러 번 눌러"하지만 난 그냥 삐 소리가 이것을 할 수있는 더 좋은 방법이 말하고 싶었다의 ..
int maxCount = 2;
int attCount = 0;
public int[] AttackTriggers; //Add the trigger ID's to the array via the editor.
public float attackResetTime = 1.0f; //Will take one second to reset counter.
if(Input.GetKeyDown(KeyCode.Q))
{
anim.SetTrigger(AttackTriggers[attCount]);
attCount++;
if(attCount > maxCount)
{
attCount = 0;
}
}
하지만 사용자가 지정된 시간 내에 Q를 누르지 않으면 attCount를 다시 0으로 재설정해야하는지 확인해야합니다. 이것은 코 루틴으로 달성 할 수 있습니다.
public IEnumerator ResetAttCount()
{
yield return new WaitForSeconds(attackResetTime);
attCount = 0;
}
이제, 우리는 시간을 기준으로 카운트를 재설정 할 수 있습니다,하지만 우리는 여전히 우리가 시작되었는지 확인하고 오른쪽 장소에서 코 루틴을 중지, 그래서 if 문 원래 약간 수정할 수해야합니다
if(Input.GetKeyDown(KeyCode.Q))
{
StopCoroutine(ResetAttCount());
anim.SetTrigger(AttackTriggers[attCount]);
attCount++;
if(attCount > maxCount)
{
attCount = 0;
}
}
을
그리고 다음의 키 업 이벤트에 대해 한 번 더 문을 추가 할 수 없습니다 :
if(Input.GetKeyUp(KeyCode.Q))
{
StartCoroutine(ResetAttCount());
}
을 아니 이제 우리는 성공적으로 키를 놓을 때 타이머를 시작하고 중지하여 공격 횟수의 리셋 타이밍 키가 1 초 이내에 다시 한번 눌려지면
클래스가 실패했습니다. – AMA91