public void KillSwordEnemy(SwordEnemy enemy) { currentEnemies--; // Subtract 1 from the current enemies alive. enemy.gameObject.SetActive(false); // Set the enemy to inactive (destroy but using an efficient object pooler). op.RequeueObject("SwordEnemy", enemy.gameObject); // Requeue the enemy into the object pooler. kills++; // Increase the amount of kills by 1. combo++; // Increase the combo by 1. score += scorePerKill + (comboBonus * (combo - 1)); resetCombo = Time.time + comboTimer; // Set the next time the combo should be reset if we don't get any kills. UpdateHUD(); // Update the HUD to reflect all of the new stats. if (kills % killsPerNewEnemy == 0 && kills <= 200) { // We have reached a new kill milestone and haven't maxed out our players yet. maxEnemyRespawnTimer = Mathf.Clamp(maxEnemyRespawnTimer - enemyRespawnDecrement, minEnemyRespawnTimer, maxEnemyRespawnTimer); // Reduce the max timer by how much we should decrement then clamp it so it doesn't go below the minimum. enemies++; // Increase the amount of enemies we are allowed to have spawned. } }
void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.name == "SwordEnemy(Clone)") { // We collided with a sword enemy. SwordEnemy swordEnemy = col.gameObject.GetComponent <SwordEnemy>(); if (deadly) { // We are currently dashing, kill enemy. gm.KillSwordEnemy(swordEnemy); } else if (swordEnemy.deadly) { // The enemy is dashing and we are vulnerable, die. gm.KillPlayer(this); } } else if (col.gameObject.name == "RangedEnemy(Clone)") { // We collided with a ranged enemy. RangedEnemy rangedEnemy = col.gameObject.GetComponent <RangedEnemy>(); if (deadly) { // We are currently dashing, kill enemy. gm.KillRangedEnemy(rangedEnemy); } } else if (col.gameObject.name == "Arrow(Clone)") { // We collided with an arrow. if (deadly) { // We are currently dashing, destroy arrow. Destroy(col.gameObject); } else { // We are currently vulnerable, die. gm.KillPlayer(this); Destroy(col.gameObject); // Destroy arrow anyway, it is inside us after all. } } }