// if an enemy is in the collision area, apply damage to that enemy private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("meleeEnemy")) { EnemyController meleeEnemy = collision.GetComponent <EnemyController>(); meleeEnemy.TakeDamage(3); GameObject aoeEffect = Instantiate(explosion, transform.position, Quaternion.identity); aoeEffect.GetComponent <Animator>().SetTrigger("Explode"); Destroy(aoeEffect, 1.0f); } if (collision.CompareTag("rangedEnemy")) { RangedEnemy rangedEnemy = collision.GetComponent <RangedEnemy>(); rangedEnemy.TakeDamage(3); GameObject aoeEffect = Instantiate(explosion, transform.position, Quaternion.identity); aoeEffect.GetComponent <Animator>().SetTrigger("Explode"); Destroy(aoeEffect, 1.0f); } if (collision.CompareTag("Boss")) { if (collision.name == "Flame Knight(Clone)") { FlameKnightController controller = collision.GetComponent <FlameKnightController>(); controller.TakeDamage(3); GameObject aoeEffect = Instantiate(explosion, transform.position, Quaternion.identity); aoeEffect.GetComponent <Animator>().SetTrigger("Explode"); Destroy(aoeEffect, 1.0f); } } }
// this handles the bullet collision // if it hits an enemy it creates an explosion effect and does damage to the enemy private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Collidables")) { Destroy(gameObject); } if (collision.CompareTag("meleeEnemy")) { // create AOE explosion effect Instantiate(aoeAttack, collision.transform.position, Quaternion.identity); Instantiate(explosionSound, collision.transform.position, Quaternion.identity); Destroy(gameObject); meleeEnemyController = collision.gameObject.GetComponent <EnemyController>(); meleeEnemyController.TakeDamage(setDamage); RoomEvent.bulletsHitEnemy += 1; GameObject hitAnimation = Instantiate(bulletHitAnimation, collision.transform.position, Quaternion.identity); hitAnimation.GetComponent <Animator>().SetTrigger("BulletHit"); Destroy(hitAnimation, 2.0f); } if (collision.CompareTag("rangedEnemy")) { // create AOE explosion effect Instantiate(aoeAttack, collision.transform.position, Quaternion.identity); Instantiate(explosionSound, collision.transform.position, Quaternion.identity); Destroy(gameObject); rangedEnemeyController = collision.gameObject.GetComponent <RangedEnemy>(); rangedEnemeyController.TakeDamage(setDamage); RoomEvent.bulletsHitEnemy += 1; GameObject hitAnimation = Instantiate(bulletHitAnimation, collision.transform.position, Quaternion.identity); hitAnimation.GetComponent <Animator>().SetTrigger("BulletHit"); Destroy(hitAnimation, 2.0f); } if (collision.CompareTag("Boss")) { print(collision.name); if (collision.name == "Flame Knight(Clone)") { FlameKnightController controller = GameObject.FindGameObjectWithTag("Boss").GetComponent <FlameKnightController>(); Instantiate(aoeAttack, transform.position, Quaternion.identity); Instantiate(explosionSound, collision.transform.position, Quaternion.identity); controller.TakeDamage(setDamage); GameObject hitAnimation = Instantiate(bulletHitAnimation, transform.position, Quaternion.identity); hitAnimation.GetComponent <Animator>().SetTrigger("BulletHit"); Destroy(gameObject); Destroy(hitAnimation, 2.0f); } } }
// checks to make sure that there is a room event active // gets references to all of the enemies in the scene and then kills them public void DestroyAllEnemies() { if (RoomEvent.roomEventActive) { RoomEvent roomEvent = GameObject.FindGameObjectWithTag("RoomEvent").GetComponent <RoomEvent>(); GameController gameController = GameObject.Find("GameController").GetComponent <GameController>(); GameObject[] meleeEnemies = GameObject.FindGameObjectsWithTag("meleeEnemy"); GameObject[] rangedEnemies = GameObject.FindGameObjectsWithTag("rangedEnemy"); Instantiate(flashHolder); foreach (GameObject meleeEnemy in meleeEnemies) { EnemyController.meleeEnemyCount -= 1; Destroy(meleeEnemy.transform.parent.gameObject); Destroy(meleeEnemy); gameController.UpdateScore(5); } foreach (GameObject rangedEnemy in rangedEnemies) { RangedEnemy.rangedEnemyCount -= 1; Destroy(rangedEnemy.transform.parent.gameObject); Destroy(rangedEnemy); gameController.UpdateScore(5); } Transform player = GameObject.FindGameObjectWithTag("Player").GetComponent <Transform>(); Instantiate(soundEffect, player.position, Quaternion.identity); Destroy(gameObject); } else if (StartBossFight.bossRoomEventActive) { GameObject boss = GameObject.FindGameObjectWithTag("Boss"); if (boss.name == "Flame Knight(Clone)") { FlameKnightController controller = boss.GetComponent <FlameKnightController>(); int maxHealth = controller.GetMaxHealth(); controller.TakeDamage(maxHealth / 2); Destroy(gameObject); } } else { // Display error message string message = "No enemies in the area."; DisplayMessage.MessageToQueue(message); } }
// checks the timers and either applies damage to the target or destroys the game object void Update() { audioSource.volume = 0.4f * GameController.sfxVolume; // run a check to see if it's time to kill the DOT if (runningSecondsToRunDOT <= 0) { Destroy(gameObject); } else { runningSecondsToRunDOT -= Time.deltaTime; } // run a check to see if it's time to apply damage if (runningSecondsToApplyDamage <= 0) { if (gameObject.transform.parent.CompareTag("meleeEnemy")) { EnemyController meleeEnemy = gameObject.transform.parent.GetComponent <EnemyController>(); meleeEnemy.PlayPoisonDamageAnimation(); audioSource.Play(); meleeEnemy.TakeDamage(2); } else if (gameObject.transform.parent.CompareTag("rangedEnemy")) { RangedEnemy rangedEnemy = gameObject.transform.parent.GetComponent <RangedEnemy>(); rangedEnemy.PlayPoisonDamageAnimation(); audioSource.Play(); rangedEnemy.TakeDamage(2); } else if (gameObject.transform.parent.CompareTag("Boss")) { if (gameObject.transform.parent.name == "Flame Knight(Clone)") { FlameKnightController controller = GameObject.FindGameObjectWithTag("Boss").GetComponent <FlameKnightController>(); controller.PlayPoisonDamageAnimation(); audioSource.Play(); controller.TakeDamage(2); } } // need to add this stuff to the boss(es). runningSecondsToApplyDamage = totalSecondsToApplyDamage; } else { runningSecondsToApplyDamage -= Time.deltaTime; } }
private void ShowHealthBar() { // Fade in the boss health bar and name bossHealthBar.gameObject.SetActive(true); bossIcon.gameObject.SetActive(true); // link in the boss controller FlameKnightController controller = GameObject.FindGameObjectWithTag("Boss").GetComponent <FlameKnightController>(); // setup the health bar controller.SetUpHealthBar(); // move on to the next section Invoke("BackToPlayer", 3.5f); }
// Start is called before the first frame update void Start() { // set the initial values boss = GameObject.FindGameObjectWithTag("Boss").GetComponent <FlameKnightController>(); timer = totalTimeBetweenShots; }