[HideInInspector] public bool commandSwitching; //don't allow commands while switching // Use this for initialization void Awake() { switch (numCommands) { case 2: Instantiate(HUD [0]); break; case 3: Instantiate(HUD [1]); break; //etc } canDash = true; hasSword = true; dashing = false; attackCombo = new bool[COMBONUM]; attacking = false; attackLock = true; dashCharges = numDashes; Physics2D.IgnoreLayerCollision(8, 9, false); //prevent invincability by dashing into transition for (int i = 0; i < COMBONUM; i++) { attackCombo[i] = false; } canAttack = true; pm = GetComponent <PlayerMovement> (); sfx = GetComponent <SFXManager> (); rb = GetComponent <Rigidbody2D> (); an = GetComponent <Animator> (); gs = GetComponent <GhostSprites> (); ps = GetComponentInChildren <PlayerSword> (); ph = GameObject.FindGameObjectWithTag("HUD").GetComponent <PlayerHUD> (); php = GetComponent <PlayerHealth> (); php.ph = ph; for (int i = 0; i < numCommands; i++) { commands [i] = Instantiate(commandsOriginals [chosenCommands[i]]).GetComponent <PlayerCommand>(); } gs.ClearTrail(); selectedCommand = 1; canCommand = true; damageColliderOriginalOffset = php.damageCollider.offset; }
// Update is called once per frame void Update() { #region Dash //End Dash (once dashTime is up) if (dashing) { dashCounter += Time.deltaTime; if (dashCounter >= dashTime) { //Dash Finished dashing = false; php.damageCollider.enabled = true; Physics2D.IgnoreLayerCollision(8, 9, false); Physics2D.IgnoreLayerCollision(8, 10, false); dashCounter = 0; rb.velocity = Vector2.zero; pm.canMove = true; pm.fallSafe = false; delayCounter += dashDelay; if (delayCounter > dashDelay * numDashes) { delayCounter = dashDelay * numDashes; } gs.ClearTrail(); gs.KillSwitchEngage(); an.SetBool("Dash", false); } else { //show dashBar being used up in the HUD CalcDashHUD(); } return; } else if (delayCounter > 0) //dash must recharge { delayCounter -= Time.deltaTime; for (int i = 1; i <= numDashes; i++) //account for overcharge { if (delayCounter < (numDashes - i) * dashDelay && delayCounter >= (numDashes - (i + 1)) * dashDelay) { dashCharges = i; } } if (dashCharges < numDashes) { ph.ShowDash(dashCharges, (delayCounter % dashDelay) / dashDelay); } else { ph.ShowDash(dashCharges - 1, 0); } } //Start Dash if (canDash && !attacking && dashCharges > 0 && Input.GetButtonDown("Dash")) { horiz = Input.GetAxis("Horizontal"); vert = Input.GetAxis("Vertical"); pm.canMove = false; pm.fallSafe = true; dashing = true; Physics2D.IgnoreLayerCollision(8, 9, true); Physics2D.IgnoreLayerCollision(8, 10, true); php.damageCollider.enabled = false; dashCounter = 0; dashCharges--; if (dashCharges == numDashes - 1) { //ph.ShowDash(dashCharges, 1); tmpDashCalc = 1f; } else { //ph.ShowDash(dashCharges, (delayCounter % dashDelay) / dashDelay); tmpDashCalc = 1 - ((delayCounter % dashDelay) / dashDelay); } //account for dash with no movement input if (horiz == 0 && vert == 0) { switch (GetDirection()) { case DOWN: rb.velocity = Vector2.down * dashSpeed; break; case LEFT: rb.velocity = Vector2.left * dashSpeed; break; case UP: rb.velocity = Vector2.up * dashSpeed; break; case RIGHT: rb.velocity = Vector2.right * dashSpeed; break; } //normal dash } else { rb.velocity = new Vector2(horiz, vert).normalized *dashSpeed; } //Dash ghost trail animation gs.killSwitch = false; an.SetBool("Dash", true); sfx.playSound(3); return; } #endregion #region BasicAttack if (hasSword) { //check for attacking spam input if (!attackLock && attacking && Input.GetButtonDown("Attack")) { attackLock = true; int i = 0; for (i = 0; i < COMBONUM; i++) { if (attackCombo[i] == true) { break; } } attackCombo [i] = false; if (i < COMBONUM - 1) { attackCombo [i + 1] = true; //make sure final combo attack doesn't set attackLock to false, else this will break } } //1st Attack if (!attacking && canAttack && Input.GetButtonDown("Attack")) { attackLock = false; attacking = true; canAttack = false; attackCombo [0] = true; pm.canMove = false; ps.comboMultiplier = damageMultiplier[0]; an.SetInteger("ComboNum", 0); an.SetTrigger("Attack"); sfx.playSound(0); switch (GetDirection()) { case DOWN: rb.velocity = Vector2.down * attackSpeed[0]; php.damageCollider.offset = new Vector2(0, damageColliderOffset); break; case LEFT: rb.velocity = Vector2.left * attackSpeed [0]; php.damageCollider.offset = new Vector2(damageColliderOffset, 0); break; case UP: rb.velocity = Vector2.up * attackSpeed [0]; php.damageCollider.offset = new Vector2(0, -damageColliderOffset); break; case RIGHT: rb.velocity = Vector2.right * attackSpeed [0]; php.damageCollider.offset = new Vector2(-damageColliderOffset, 0); break; } } //allow direction change if (attacking) { SetDirection(); } //2nd Attack if (attackLock && canAttack && attackCombo[1]) { attackLock = false; canAttack = false; ps.comboMultiplier = damageMultiplier[1]; an.SetInteger("ComboNum", 1); an.SetTrigger("Attack"); sfx.playSound(1); switch (GetDirection()) { case DOWN: rb.velocity = new Vector2(horiz, -1).normalized *attackSpeed[1]; break; case LEFT: rb.velocity = new Vector2(-1, vert).normalized *attackSpeed [1]; break; case UP: rb.velocity = new Vector2(horiz, 1).normalized *attackSpeed [1]; break; case RIGHT: rb.velocity = new Vector2(1, vert).normalized *attackSpeed [1]; break; } } //3rd Attack if (attackLock && canAttack && attackCombo[2]) { attackLock = false; canAttack = false; an.SetInteger("ComboNum", 2); an.SetTrigger("Attack"); sfx.playSound(2); ps.comboMultiplier = damageMultiplier[2]; switch (GetDirection()) { case DOWN: rb.velocity = new Vector2(horiz / 2, -1).normalized *attackSpeed[2]; break; case LEFT: rb.velocity = new Vector2(-1, vert / 2).normalized *attackSpeed [2]; break; case UP: rb.velocity = new Vector2(horiz / 2, 1).normalized *attackSpeed [2]; break; case RIGHT: rb.velocity = new Vector2(1, vert / 2).normalized *attackSpeed [2]; break; } } } #endregion #region Commands //check for command input if (hasSword && !commandSwitching && canCommand && Input.GetButtonDown("UseCommand")) { if (commands[selectedCommand].canUse) { //Use the selected command commands[selectedCommand].UseCommand(); //ph.ChangeCommand(); } else { //show error with sound effect and/or quick animation } } #endregion }