// run through each active enemy and reduce their speed values private void SlowDownEnemyTime() { if (RoomEvent.roomEventActive) { foreach (GameObject meleeEnemy in meleeEnemies) { meleeEnemy.GetComponent <EnemyController>().startTimeBetweenAttacks = normalAttackSpeed + 5.0f; meleeEnemy.transform.parent.GetComponent <Unit>().speed = normalWalkSpeed * .1f; } foreach (GameObject rangedEnemy in rangedEnemies) { rangedEnemy.GetComponent <RangedEnemy>().bulletSpeed = normalBulletSpeed * .1f; } } else if (StartBossFight.bossRoomEventActive) { GameObject boss = GameObject.FindGameObjectWithTag("Boss"); if (boss.name == "Flame Knight(Clone)") { FlameKnightMoveToAreaAttack moveToAreaAttackSpeed = boss.GetComponent <Animator>().GetBehaviour <FlameKnightMoveToAreaAttack>(); FlameKnightPrepForCircleAttack prepForCircleAttack = boss.GetComponent <Animator>().GetBehaviour <FlameKnightPrepForCircleAttack>(); FlameKnightCircleAttack circleAttack = boss.GetComponent <Animator>().GetBehaviour <FlameKnightCircleAttack>(); moveToAreaAttackSpeed.speed = normalBossSpeedOne * .1f; prepForCircleAttack.speed = normalBossSpeedOne * .1f; circleAttack.speed = normalBossSpeedTwo * .1f; } } }
// once the enemy leaves the collision area, set their speed back to normal private void OnTriggerExit2D(Collider2D collision) { if (RoomEvent.roomEventActive) { // enemies are sped back up if (collision.CompareTag("meleeEnemy")) { collision.transform.parent.GetComponent <Unit>().speed = normalSpeed; } } else if (StartBossFight.bossRoomEventActive) { if (collision.CompareTag("Boss")) { if (collision.name == "Flame Knight(Clone)") { GameObject flameKnight = GameObject.FindGameObjectWithTag("Boss"); FlameKnightMoveToAreaAttack moveToAreaAttackSpeed = flameKnight.GetComponent <Animator>().GetBehaviour <FlameKnightMoveToAreaAttack>(); FlameKnightPrepForCircleAttack prepForCircleAttack = flameKnight.GetComponent <Animator>().GetBehaviour <FlameKnightPrepForCircleAttack>(); FlameKnightCircleAttack circleAttack = flameKnight.GetComponent <Animator>().GetBehaviour <FlameKnightCircleAttack>(); moveToAreaAttackSpeed.speed = bossSpeedOne; prepForCircleAttack.speed = bossSpeedOne; circleAttack.speed = bossSpeedTwo; } } } }
// when an enemy walks into the collision area, reduce their speed to 10% of normal private void OnTriggerEnter2D(Collider2D collision) { // melee enemies will slow down if (RoomEvent.roomEventActive) { if (collision.CompareTag("meleeEnemy")) { if (normalSpeed == 0) { normalSpeed = collision.transform.parent.GetComponent <Unit>().speed; } collision.transform.parent.GetComponent <Unit>().speed = normalSpeed * .1f; } } else if (StartBossFight.bossRoomEventActive) { if (collision.CompareTag("Boss")) { if (collision.name == "Flame Knight(Clone)") { GameObject flameKnight = GameObject.FindGameObjectWithTag("Boss"); FlameKnightMoveToAreaAttack moveToAreaAttackSpeed = flameKnight.GetComponent <Animator>().GetBehaviour <FlameKnightMoveToAreaAttack>(); FlameKnightPrepForCircleAttack prepForCircleAttack = flameKnight.GetComponent <Animator>().GetBehaviour <FlameKnightPrepForCircleAttack>(); FlameKnightCircleAttack circleAttack = flameKnight.GetComponent <Animator>().GetBehaviour <FlameKnightCircleAttack>(); if (bossSpeedOne == 0 && bossSpeedTwo == 0) { bossSpeedOne = moveToAreaAttackSpeed.speed; bossSpeedTwo = circleAttack.speed; } moveToAreaAttackSpeed.speed = moveToAreaAttackSpeed.speed * .1f; prepForCircleAttack.speed = prepForCircleAttack.speed * .1f; circleAttack.speed = circleAttack.speed * .1f; } } } }
// Grab references to all of the enemies, get their normal speed values and then slow them way down void Start() { timer = totalTimeToRunTimeSlow; if (RoomEvent.roomEventActive) { meleeEnemies = GameObject.FindGameObjectsWithTag("meleeEnemy"); rangedEnemies = GameObject.FindGameObjectsWithTag("rangedEnemy"); if (rangedEnemies.Length != 0) { normalBulletSpeed = rangedEnemies[0].GetComponent <RangedEnemy>().bulletSpeed; } if (meleeEnemies.Length != 0) { normalAttackSpeed = meleeEnemies[0].GetComponent <EnemyController>().startTimeBetweenAttacks; normalWalkSpeed = meleeEnemies[0].transform.parent.GetComponent <Unit>().speed; } } else if (StartBossFight.bossRoomEventActive) { GameObject boss = GameObject.FindGameObjectWithTag("Boss"); if (boss.name == "Flame Knight(Clone)") { FlameKnightMoveToAreaAttack moveToAreaAttackSpeed = boss.GetComponent <Animator>().GetBehaviour <FlameKnightMoveToAreaAttack>(); FlameKnightPrepForCircleAttack prepForCircleAttack = boss.GetComponent <Animator>().GetBehaviour <FlameKnightPrepForCircleAttack>(); FlameKnightCircleAttack circleAttack = boss.GetComponent <Animator>().GetBehaviour <FlameKnightCircleAttack>(); normalBossSpeedOne = moveToAreaAttackSpeed.speed; normalBossSpeedTwo = circleAttack.speed; } } SlowDownEnemyTime(); }