protected virtual IEnumerator StunEnemy(float stunDuration) { if (!enStunned) { enStunned = true; enCanAttack = false; EnDisableMove(); if (EnAnimator != null) { EnAnimator.PlayStunned(); } if (stunLParticlePrefab != null && stunRParticlePrefab != null) { //Vector3 changeLocation = GetComponent<Transform>().position; //Vector3 tempLocation = changeLocation; Vector3 tempLocation = transform.position; tempLocation.y += .5f; if (enFacingRight) { Instantiate(stunLParticlePrefab, tempLocation, Quaternion.identity, transform); } else { Instantiate(stunRParticlePrefab, tempLocation, Quaternion.identity, transform); } } if (isAlive) { Vector3 tempPos = transform.position; tempPos.y -= TPOffset; AttackIndicator.ShowStun(tempPos, .8f); } yield return(new WaitForSeconds(stunDuration)); yield return(new WaitForSeconds(.3f)); //time for recover animation, or short delay before moving again enStunned = false; enCanAttack = true; isAttacking = false; //in case of attack interrupted from stun EnEnableMove(); EnEnableFlip(); //precaution in case enemy is stunned during attack and can't flip allowStun = Time.time + allowStunCD; } }
IEnumerator StunEnemy(float stunDuration) { if (!enStunned) { enStunned = true; //StartIdling(stunDuration + .5f, false, true); enCanAttack = false; enCanMove = false; isIdling = false; if (stunLParticlePrefab != null && stunRParticlePrefab != null) { Vector3 changeLocation = GetComponent <Transform>().position; Vector3 tempLocation = changeLocation; tempLocation.y += .5f; if (enFacingRight) { Instantiate(stunLParticlePrefab, tempLocation, Quaternion.identity, transform); } else { Instantiate(stunRParticlePrefab, tempLocation, Quaternion.identity, transform); } } if (isAlive) { Vector3 tempPos = transform.position; //tempPos += TPOffset; tempPos.y -= .4f; AttackIndicator.ShowStun(tempPos, .8f); } yield return(new WaitForSeconds(stunDuration)); yield return(new WaitForSeconds(.3f)); //time for recover animation isIdling = true; isAttacking = false; enCanAttack = true; EnEnableMove(); EnEnableFlip(); //precaution in case enemy is stunned during attack and can't flip enStunned = false; allowStun = Time.time + allowStunCD; } }