/// <summary> /// This is the function that enacts the actual light1 attack. /// </summary> /// <returns></returns> IEnumerator light1() { animator.SetBool("attacking", true); animator.SetTrigger("light1"); StartCoroutine(delayedCycle((light_time.x + light_time.y) / 2 + 0.01f)); LockAttack(light_time.x + (light_time.y / 2) + 0.01f, false, false); yield return(new WaitForSeconds(light_time.x)); // Wait specified time before starting the attack if (hitboxDamage != null) { Destroy(hitboxDamage.gameObject); //Destroy any pre-existing damage hitbox to start this attack. } if (hitboxDeflect != null) { Destroy(hitboxDeflect.gameObject); //Destroy any pre-existing deflection hitbox to start this attack. } List <Enemy> collidedCreatures; List <Projectile> collidedBullets; hitboxDamage = Instantiate(prefabsDamage[0]).GetComponent <Hitbox>(); hitboxDeflect = Instantiate(prefabsDeflect[0]).GetComponent <Hitbox>(); hitboxDamage.transform.parent = transform; hitboxDeflect.transform.parent = transform; hitboxDamage.setPosAuto(true); hitboxDeflect.setPosAuto(true); float totalTime = 0; collidedCreatures = getEnemies(hitboxDamage.collidedObjects(enemyLayerMask)); collidedBullets = getProjectiles(hitboxDeflect.collidedObjects(projectileLayerMask)); foreach (Enemy enemy in collidedCreatures) { Debug.Log(enemy.gameObject); enemy.Damage(attackDamages[0]); player.ResetDash(); player.Hover(floatTime); } foreach (Projectile projectile in collidedBullets) { projectile.Deflect(); player.ResetDash(); player.Hover(floatTime); } comboCounter.updateComboCount(collidedCreatures.Count + collidedBullets.Count); yield return(new WaitForEndOfFrame()); while (totalTime <= light_time.y) //Check how long has passed { totalTime += Time.deltaTime; //Increase the time for the while loop. //Debug.Log(Time.deltaTime + ":" + totalTime + ":" + light_time.y); List <Enemy> tempEnemies = newEnemies(collidedCreatures, getEnemies(hitboxDamage.collidedObjects(enemyLayerMask))); //Temparory list of the new un-checked enemies List <Projectile> tempProjectiles = newProjectiles(collidedBullets, getProjectiles(hitboxDamage.collidedObjects(projectileLayerMask))); //Temparory list of the new un-checked projectiles collidedCreatures.AddRange(tempEnemies); //Adding the new enemies to the total list to make sure no enemy is damaged twice. collidedBullets.AddRange(tempProjectiles); //Adding the new projectile to the total list to make sure no projectile is deflected twice. foreach (Enemy enemy in tempEnemies) { enemy.Damage(attackDamages[0]); player.ResetDash(); player.Hover(floatTime); } foreach (Projectile projectile in tempProjectiles) { projectile.Deflect(); player.ResetDash(); player.Hover(floatTime); } comboCounter.updateComboCount(tempEnemies.Count + tempProjectiles.Count); //Update the combo counter with the new collided creatures. yield return(new WaitForEndOfFrame()); //Wait for the end of the frame to act again. } Destroy(hitboxDamage.gameObject); Destroy(hitboxDeflect.gameObject); activeAttack = null; animator.SetBool("attacking", false); }