public IEnumerator abilityActionSequence() { //Wait until the attack frame in the animation has been reached while (!caster.getAttackTrigger().hasAttackTriggered()) { yield return(null); } caster.getAttackTrigger().resetTrigger(); //After shot nudge caster back a tad caster.rb2D.AddForce(direction * abilityVelocity / Time.timeScale); //Instantiate Bullet Bullet b = ObjectPool.instance.getBullet(); //Setup and turn on bullet b.gameObject.SetActive(true); b.Setup(caster, abilityDamage, stunTime, direction); caster.canCombo = false; caster.canMove = true; caster.attacking = false; }
public IEnumerator abilityActionSequence() { caster.rb2D.AddForce(direction * abilityVelocity / Time.timeScale); while (!caster.getAttackTrigger().hasAttackTriggered()) { yield return(null); } caster.getAttackTrigger().resetTrigger(); //Check if attack can go through if (!caster.isDead()) { Vector2 newPos = new Vector2(caster.transform.position.x, caster.transform.position.y + caster.objectHeight / 2); RaycastHit2D[] hitObject = Physics2D.RaycastAll(newPos, direction, abilityRange, CMoveCombatable.attackMask, -10, 10); Debug.DrawRay(newPos, direction * abilityRange, Color.red, 3f); bool hitTarget = false; //If the Raycast hits an object on the layer Enemy foreach (RaycastHit2D r in hitObject) { if (r && r.transform.gameObject != caster.gameObject) { //If an object has been hit first if (r.transform.gameObject.tag == "Object") { if (r.collider.isTrigger) { continue; } else { break; } } //Hit attack CHitable objectHit = r.transform.gameObject.GetComponentInParent <CHitable>(); if (objectHit.tag == caster.tag) { continue; } //Apply damage and knockback objectHit.setAttacker(caster); objectHit.knockback(pos, abilityKnockback, objectHit.objectHeight); //Need to use original pos for knockback so the position of where you attacked from is the knockback objectHit.knockUp(pos, abilityKnockback, abilityKnockUp, objectHit.objectHeight); objectHit.loseHealth(abilityDamage); caster.audioSource.clip = caster.attackSound; caster.audioSource.Play(); caster.attackHit(); hitTarget = true; break; } } if (!hitTarget) { caster.audioSource.clip = caster.missSound; caster.audioSource.Play(); } if (caster.pauseAfterAttack < 0.5f) { yield return(new WaitForSeconds(0.5f)); } else { yield return(new WaitForSeconds(caster.pauseAfterAttack)); } } caster.canMove = true; caster.attacking = false; caster.canCombo = false; }
public IEnumerator abilityActionSequence() { //Wait until the attack frame in the animation has been reached while (!caster.getAttackTrigger().hasAttackTriggered()) { yield return(null); } caster.getAttackTrigger().resetTrigger(); //Check if attack can go through if (!caster.isDead()) { Vector2 newPos = new Vector2(caster.transform.position.x, caster.transform.position.y + caster.objectHeight / 2); RaycastHit2D[] hitObject = Physics2D.RaycastAll(newPos, direction, abilityRange, CMoveCombatable.attackMask, -10, 10); Debug.DrawRay(newPos, direction * abilityRange, Color.black, 3f); bool hitTarget = false; //If the Raycast hits an object on the layer Enemy foreach (RaycastHit2D r in hitObject) { if (r && r.transform.gameObject != caster.gameObject && caster.attacking) { //If an object has been hit first if (r.transform.gameObject.tag == "Object") { if (r.collider.isTrigger) { continue; } else { break; } } //Hit attack CHitable objectHit = r.transform.gameObject.GetComponentInParent <CHitable>(); if (objectHit.isInvuln() || objectHit.tag == caster.tag || objectHit.isKnockedback()) //Add faction to hitables to use here instead of tags { continue; } //Set attacker and info on hit objectHit.setAttacker(caster); objectHit.lastAttackInfo = "A basic hit"; //objectHit.knockback(pos, abilityKnockback, objectHit.objectHeight); //Need to use original pos for knockback so the position of where you attacked from is the knockback objectHit.loseHealth(abilityDamage); //Apply stun to the target objectHit.applyStun(stunTime); caster.audioSource.clip = caster.attackSound; caster.audioSource.Play(); caster.attackHit(); lastAttack = Time.time; //caster.canCombo = true; caster.setComboAnimation(true); hitTarget = true; break; } } if (!hitTarget) { caster.audioSource.clip = caster.missSound; caster.audioSource.Play(); } //Wait till attack animation is over while (!caster.getAttackTrigger().isAttackOver()) { yield return(null); } caster.getAttackTrigger().resetAttack(); } if (caster.canCombo) { caster.attack(comboAttack); yield break; } else { //Pause for caster yield return(new WaitForSeconds(caster.pauseAfterAttack)); caster.setComboAnimation(false); } caster.canCombo = false; caster.canMove = true; caster.attacking = false; }