protected void GetHit(bool isRight, float damage, bool doKnockback) { if (state == State.Dead) { return; } health -= damage; if (health <= 0) { if (state != State.Dead) { SetDead(isRight, this.GetType()); } target.GetComponent <Player>().AddEnemyKilledToCount(this.GetType()); } else { if (!doKnockback) { SetStaggered(isRight); } else { SetKnockedBack(isRight); } } soundManager.PlayOneShot(getHitSound); cameraController.Shake(damage); ParticleEffectManager.PlayEffect(ParticleEffect.Type.blood, coll.bounds.center, isRight ? Vector3.left : Vector3.right); }
void ShootProjectileEvent() { soundManager.PlayOneShot(projectileSummonSound); Instantiate(projectilePrefab, transform.parent).GetComponent <Projectile>() .Set(projectileSpawnPoint.position, new Vector2(coll.bounds.center.x < target.position.x ? 1 : -1, 0), "EnemyWeapon", target.position, projectileSpeed, projectileDamage); }
IEnumerator CastWhirlwind(float windUpTime, float castTime, float cooldownTime) { animator.SetBool("IsWindingUpWhirlwind", true); SetImmobilized(); yield return(new WaitForSecondsRealtime(windUpTime)); spawnedWhirlwindObject = Instantiate(whirlwindEffectPrefab, transform.parent); spawnedWhirlwindObject.GetComponent <NagaKingWhirlwindEffect>().Set(coll.bounds.center, castTime); damageContainer.SetDamageCall(() => whirlwindAttackDamage); animator.SetBool("IsChannellingWhirlwind", true); animator.SetBool("IsWindingUpWhirlwind", false); SetImmobilized(); PlayWhirlwindAttackEffect(); yield return(new WaitForSecondsRealtime(castTime)); animator.SetBool("IsChannellingWhirlwind", false); damageContainer.SetDamageCall(() => touchDamage); Instantiate(explosionBeforeShockwavePrefab, coll.bounds.center, Quaternion.identity, transform.parent).GetComponent <ParticleSystem>().Play(); Vector2 shockwaveOrigin = coll.bounds.center; shockwaveOrigin.y = coll.bounds.min.y; Instantiate(shockwavePrefab, transform.parent).GetComponent <Shockwave>().Set(shockwaveOrigin, 3f, Vector2.right, shockwaveDamage); Instantiate(shockwavePrefab, transform.parent).GetComponent <Shockwave>().Set(shockwaveOrigin, 3f, Vector2.left, shockwaveDamage); sound.PlayOneShot(shockwaveExplosionSound); canCastWirldwind = false; yield return(new WaitForSecondsRealtime(cooldownTime)); canCastWirldwind = true; }
protected void GetHit(bool isRight, float damage) { if (state == State.Dead) { return; } health -= damage; if (health <= 0) { StopAllCoroutines(); nagaManager.EnrageFemaleNaga(); SetDead(isRight, this.GetType(), 0); nagaManager.Died(false); animator.SetBool("IsChannellingWhirlwind", false); animator.SetBool("IsWindingUpWhirlwind", false); this.enabled = false; nagaManager.HideHealthbar(false); if (spawnedWhirlwindObject != null) { spawnedWhirlwindObject.GetComponent <NagaKingWhirlwindEffect>().Stop(); } target.GetComponent <Player>().AddEnemyKilledToCount(this.GetType()); } else { bool stagger = false; if (staggerCounter + 1 <= maxStaggerCount) { stagger = true; } if (stagger) { staggerCounter += 1; SetStaggered(isRight); } nagaManager.UpdateHealthbar(false, health, maxHealth); } sound.PlayOneShot(getHitSound); cameraController.Shake(damage); ParticleEffectManager.PlayEffect(ParticleEffect.Type.blood, coll.bounds.center, isRight ? Vector3.left : Vector3.right); }
protected void GetHit(bool isRight, float damage) { if (state == State.Dead || !canTakeDamage) { return; } health -= damage; if (health <= 0) { StopAllCoroutines(); SetDead(isRight, this.GetType()); nagaManager.Died(true); nagaManager.StopPlayingBossMusic(); nagaManager.HideHealthbar(true); target.GetComponent <Player>().AddEnemyKilledToCount(this.GetType()); } Teleport(); nagaManager.UpdateHealthbar(true, health, maxHealth); sound.PlayOneShot(getHitSound); cameraController.Shake(damage); ParticleEffectManager.PlayEffect(ParticleEffect.Type.blood, coll.bounds.center, isRight ? Vector3.left : Vector3.right); }
protected void GetHit(bool isRight, float damage) { if (state == State.Dead) { return; } health -= damage; if (health <= 0) { StopAllCoroutines(); nagaManager.EnrageMaleNaga(); SetDead(isRight, this.GetType(), 0); nagaManager.Died(true); nagaManager.HideHealthbar(true); this.enabled = false; target.GetComponent <Player>().AddEnemyKilledToCount(this.GetType()); } else { bool stagger = false; if (staggerCounter + 1 <= maxStaggerCount) { stagger = true; } if (stagger) { staggerCounter += 1; SetStaggered(isRight); } nagaManager.UpdateHealthbar(true, health, maxHealth); } sound.PlayOneShot(getHitSound); cameraController.Shake(damage); ParticleEffectManager.PlayEffect(ParticleEffect.Type.blood, coll.bounds.center, isRight ? Vector3.left : Vector3.right); }
void Land() { Vector2 shockwaveOrigin = coll.bounds.center; shockwaveOrigin.y = coll.bounds.min.y; Instantiate(shockwavePrefab, transform.parent).GetComponent <Shockwave>().Set(shockwaveOrigin, 3f, Vector2.right, shockwaveDamage); Instantiate(shockwavePrefab, transform.parent).GetComponent <Shockwave>().Set(shockwaveOrigin, 3f, Vector2.left, shockwaveDamage); cameraController.Shake(10); StartCoroutine(SetImmobilizeFor(landImmobalizedTime)); sound.PlayOneShot(landSound); }
void Update() { isGrounded = IsGrounded(terrainMask); switch (state) { case State.Aggro: bool inLineWithPlayer = RaycastToPlayer(isDirRight, aggroRange, playerTag, playerMask, terrainMask) || RaycastToPlayer(!isDirRight, aggroRange, playerTag, playerMask, terrainMask); float dist = Vector2.Distance(transform.position, target.position); bool goundInFrontExists = DoesGroundForwardExists(isDirRight, yRayLength, terrainMask); float yDiff = target.position.y - transform.position.y; if (!goundInFrontExists && isGrounded && yDiff >= -coll.bounds.extents.y) { AttackJump(); } else if (isGrounded && RaycastSideways_OR(isDirRight, 3, xRayLength, terrainMask)) { AttackJump(); } else if (inLineWithPlayer) // player on the same level as enemy { if (target.position.x < transform.position.x) { if (isDirRight) { ChangeDirection(false); } } else { if (!isDirRight) { ChangeDirection(true); } } if (!isNextDoubleAttack && Vector2.Distance(target.position, transform.position) < attackRange) { AttackSingle(); } else if (isNextDoubleAttack && Vector2.Distance(target.position, transform.position) < doubleAttackRange) { AttackDouble(); } } else // player is either higher or lower { if (yDiff > maxYDiff) { SetIdle(); } else { if (isGrounded && yDiff >= minYJumpDist && yDiff < maxYJumpDist && dist >= minJumpRange && dist < maxJumpRange) // player is higher - perform jump to it { AttackJump(); } else if (isNextDoubleAttack && dist < doubleAttackRange) { AttackDouble(); } else if (!isNextDoubleAttack && dist < attackRange) { AttackSingle(); } } } break; case State.Attacking: break; case State.KnockedBack: if (isGrounded && fullyKnockedDown && state != State.Dead) { EndKnockedBack(); } break; case State.Idle: if (Vector2.Distance(transform.position, target.position) < aggroRange) { if (RaycastToPlayer(isDirRight, aggroRange, playerTag, playerMask, terrainMask) || RaycastToPlayer(!isDirRight, aggroRange, playerTag, playerMask, terrainMask)) { SetAggro(); aggroRange *= 5; } } break; case State.Dead: break; case State.Awakening: break; case State.Jumping: minJumpTimer -= Time.deltaTime; if (isGrounded && minJumpTimer <= 0) { StartCoroutine(SetImmobilizeFor(landImmobalizedTime)); soundManager.PlayOneShot(landSound); } break; case State.Immobilized: break; case State.Falling: minJumpTimer -= Time.deltaTime; if (isGrounded && minJumpTimer <= 0) { damageContainer.SetDamageCall(() => touchDamage); StartCoroutine(SetImmobilizeFor(landImmobalizedTime)); soundManager.PlayOneShot(landSound); } break; } animator.SetBool("Is Grounded", isGrounded); animator.SetFloat("Vertical Velocity", rb.velocity.y); animator.SetFloat("Horizontal Velocity", Mathf.Abs(rb.velocity.x)); }