private void Update() { if (currentAttack != null) { if (attackTimer > 0) { attackTimer -= Time.deltaTime; } else { currentAttack = null; } return; } if (currentCombos.Count > 0) { leewayTimer += Time.deltaTime; if (leewayTimer >= comboLeeway) { if (lastInput != null) { Attack(GetAttackFromType(lastInput.attackType)); lastInput = null; } ResetCombos(); } } else { leewayTimer = 0; } ComboInput currentInput = null; if (Input.GetKeyDown(lightKey)) { currentInput = new ComboInput(AttackType.Light); } if (Input.GetKeyDown(heavyKey)) { currentInput = new ComboInput(AttackType.Heavy); } if (Input.GetKeyDown(specialKey)) { currentInput = new ComboInput(AttackType.Special); } if (currentInput == null) { return; } lastInput = currentInput; List <int> removeList = new List <int>(); for (int i = 0; i < currentCombos.Count; i++) { Combo combo = combos[currentCombos[i]]; if (combo.ShouldContinueCombo(currentInput)) { leewayTimer = 0; } else { removeList.Add(i); } } if (shouldSkipFrame) { //to prevent problems with update loop when calling ResetCombos() shouldSkipFrame = false; return; } for (int i = 0; i < combos.Count; i++) { if (currentCombos.Contains(i)) { continue; } if (combos[i].ShouldContinueCombo(currentInput)) { currentCombos.Add(i); leewayTimer = 0; } } foreach (int i in removeList) { currentCombos.RemoveAt(i); } if (currentCombos.Count <= 0) { Attack(GetAttackFromType(currentInput.attackType)); } }
private void Attack(Attack attack) { currentAttack = attack; attackTimer = attack.length; animator.Play(attack.name, -1, 0); }