The question is answered, right answer was accepted
Combo Animation interruption
Hello everyone, this is my first time posting here. I've been looking around on the site and haven't found a clear cut answer. I'm not saying it's not out there, but I haven't been able to find an answer. Basically, I'm a novice when it comes to Unity animation. My combos all seem to hit the enemy, however, the animations don't always play and the hits seem to land regardless of whether the animation plays or not. I have a feeling that's it's mostly due to the way my IEnumerator's are set up in order for the animations to play for a certain period of time instead of constantly playing. Currently, I'm able to get the first 2 animations playing but the third is not. Here is my code. Please feel free to call out redundancies as well how messy my code is. I haven't done this in a long time and am going back to school in January. Any and all help would be appreciated!
void Update()
{
if(Input.GetKey("t"))
{
comboCount = 1;
attack1 = true;
attack2 = true;
attack3 = true;
}
if(Input.GetKey("j") && comboCount == 1 && attack1)
{
time = Time.deltaTime;
StartCoroutine("Attack1");
Collider2D[] enemiesToDamage = Physics2D.OverlapCircleAll(attackPos.position, attackRange, whatIsEnemies);
for (int i = 0; i < enemiesToDamage.Length; i++)
{
enemiesToDamage[i].GetComponent<Enemy>().receiveDamage(damage);
OnTriggerEnter2D(enemiesToDamage[i]);
}
//timeBtwAttack = startTimeBtwAttack;
}
Debug.Log(attack1 + " " + attack2 + " " + attack3);
if (attack1 == false && Input.GetKey("j") && comboCount == 2)
{
StartCoroutine("Attack2");
Collider2D[] enemiesToDamage = Physics2D.OverlapCircleAll(attackPos.position, attackRange, whatIsEnemies);
for (int i = 0; i < enemiesToDamage.Length; i++)
{
enemiesToDamage[i].GetComponent<Enemy>().receiveDamage(damage);
OnTriggerEnter2D(enemiesToDamage[i]);
}
}
if (attack2 == false && Input.GetKey("j") && comboCount == 3)
{
StartCoroutine("Attack3");
Collider2D[] enemiesToDamage = Physics2D.OverlapCircleAll(attackPos.position, attackRange, whatIsEnemies);
for (int i = 0; i < enemiesToDamage.Length; i++)
{
enemiesToDamage[i].GetComponent<Enemy>().receiveDamage(damage);
OnTriggerEnter2D(enemiesToDamage[i]);
}
}
//else
//{
// timeBtwAttack -= Time.deltaTime;
//}
}
void OnDrawGizmosSelected()
{
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(attackPos.position, attackRange);
}
IEnumerator Attack1()
{
playerAnim.SetBool("isAttacking1", true);
yield return new WaitForSeconds(0.15f);
playerAnim.SetBool("isAttacking1", false);
}
IEnumerator Attack2()
{
playerAnim.SetBool("isAttacking1", false);
playerAnim.SetBool("isAttacking2", true);
yield return new WaitForSeconds(0.15f);
playerAnim.SetBool("isAttacking2", false);
}
IEnumerator Attack3()
{
playerAnim.SetBool("isAttacking2", false);
playerAnim.SetBool("isAttacking3", true);
yield return new WaitForSeconds(0.15f);
playerAnim.SetBool("isAttacking3", false);
}
public void OnTriggerEnter2D(Collider2D enemy)
{
if(enemy.gameObject.tag == "Boss")
{
enemyHit = true;
if (comboCount == 1)
{
Invoke("disableAttack1", .1f);
}
if (comboCount == 2)
{
Invoke("disableAttack2", .1F);
}
}
}
void disableAttack1()
{
if (comboCount == 1)
{
attack1 = false;
comboCount++;
}
}
void disableAttack2()
{
if (comboCount == 2)
{
attack2 = false;
comboCount++;
}
}
void comboWait()
{
comboCount++;
}
void resetCombo()
{
comboCount = 1;
}
}
Have you looked into Animation Event? You can place events in the animation timeline https://docs.unity3d.com/$$anonymous$$anual/animeditor-AnimationEvents.html
I have not, but I will now! Thank you for the tip!
Hey, I got things figured out with Animation Events. Just wanted to say thanks again!