public void ReceiveHit(bool throughFeet) { if (invuln != null && !invuln.IsInvulnerable()) { AudioManager.GetInstance().PlayEffect(Sfx.ENEMY_HIT); if (deathType == DeathType.SLIME || deathType == DeathType.DIVIDE) { if (hits > 0) { var enemyComponent = GetComponent <Enemy>(); SpawnChildren(enemyComponent); } else { KillEnemy(throughFeet); } } else { hits--; if (hits <= 0) { KillEnemy(throughFeet); } else { invuln.SetInvulnerable(GameplayValues.GetEnemyInvulnerableTime()); } } } }
// Specific death that creates smaller children with 1 hit point less. private void SpawnChildren(Enemy enemyComponent) { MarkAsDead(); var pos = enemyComponent != null? enemyComponent.initialPosition : gameObject.transform.position; var firstChild = Instantiate(gameObject, new Vector2(pos.x - 0.23f, pos.y - 0.07f), gameObject.transform.rotation); var secondChild = Instantiate(gameObject, new Vector2(pos.x + 0.23f, pos.y - 0.07f), gameObject.transform.rotation); // Make them smaller. var theScale = firstChild.transform.localScale; firstChild.transform.localScale = new Vector3(theScale.x * 0.75f, theScale.y * 0.75f, theScale.z); theScale = secondChild.transform.localScale; secondChild.transform.localScale = new Vector3(theScale.x * 0.75f, theScale.y * 0.75f, theScale.z); gameObject.SetActive(false); // Make the children invulnerable. firstChild.GetComponent <EnemyInvulnerability>().SetInvulnerable(GameplayValues.GetEnemyInvulnerableTime()); secondChild.GetComponent <EnemyInvulnerability>().SetInvulnerable(GameplayValues.GetEnemyInvulnerableTime()); // Give them the hitpoints. firstChild.GetComponent <PlayerHitReceiver>().hits = hits - 1; secondChild.GetComponent <PlayerHitReceiver>().hits = hits - 1; }