how to make a splitter enemy

Im trying to make an enemy that multiplies itself once its hp reaches 0, sounded simple at first but its kinda complicated.

im just testing around so all i have for now is on enemy death, i instantiate another of himself and destroy the gameObject.

Problems are:
how do i check how many times the enemy has been split in order to stop it from happening?
even if i add a counter each instantiated prefab will have a fresh counter.
im thinking of doing more than one prefab for each split but isnt there another way to do it?

also how can i check(due to collisions with other enemies with rigidbody or itself) that where im splitting is a ‘safe’ place to avoid spawning on top of another enemy?

ok, let me see if i get it, you want some enemy (a goo maybe?) that when killed split in two (or more) smaller versions, and these, when killed, split again, right?

i think the easiest way would to, like you said, make 3 prefabs (full goo, half goo, quarter goo), each with a OnDestroy override that instantiate the next enemy (full >> half >> quarter), except for the last one

if you dont want to do that you can try creating a empty object with some kind of enemy manager, that has a int[#splitable_enemies] variable to store how many times each enemy was killed, but this would be more cpu and ram consuming

for checking that your enemy is spawning in a proper place, you can try this

function OnEnable ()

{

var enemies : GameObject[] = GameObject.FindGameObjectsWithTag("enemy");
for (var enemy_ in enemies)
{
	var point : Vector3 = enemy_.collider.ClosestPointOnBounds(gameObject.transform.position);
	if (enemy_.transform.position != gameObject.transform.position && Vector3.Distance(point,gameObject.transform.position) < 1)
	gameObject.transform.Translate(Vector3(5,0,0)); 
}

}

its probably not the best way to do it, but i tested and it works (it doesnt check it its inside a box, or if crossed some wall, but it already takes care of not respawning in another enemy)

umm, lol nevermind that question, i did the 2nd thing i came up with; creating 3 different prefab for each division and got it working, just dont think its very performance friendly :confused: