/// <summary> /// Raises the trigger enter2d event. /// Both when the player laser hits the ship and when they hit the garbage collector /// </summary> /// <param name="col">Collider</param> void OnTriggerEnter2D(Collider2D col) { playerLaserControl playerLaser = col.gameObject.GetComponent <playerLaserControl> (); Destroyer enemyDestroyer = col.gameObject.GetComponent <Destroyer>(); if (playerLaser) { GameObject explosion = Instantiate(explosionPrefab) as GameObject; explosion.transform.position = this.transform.position; Destroy(col.gameObject); scoreboard.addScore(GameConstants.ENEMY_ONE_VALUE); Destroy(this.gameObject); } if (enemyDestroyer) { Destroy(this.gameObject); } }
/// <summary> /// Raises the trigger enter2d event. /// Both when the player laser hits the ship and when they hit the garbage collector /// </summary> /// <param name="col">Collider</param> void OnTriggerEnter2D(Collider2D col) { playerLaserControl playerLaser = col.gameObject.GetComponent <playerLaserControl> (); Destroyer enemyDestroyer = col.gameObject.GetComponent <Destroyer>(); if (playerLaser) { Destroy(col.gameObject); //This destroys the player laser. hit.Play(); health -= GameConstants.PLAYER_DAMAGE; if (health <= 0) { GameObject explosion = Instantiate(explosionPrefab) as GameObject; explosion.transform.position = this.transform.position; scoreboard.addScore(GameConstants.ENEMY_TWO_VALUE); Destroy(this.gameObject); } } //TODO: Make the enemy ships not overlap each other. (Bounce) }