switch prefab on collision

hello and thank you in advance for the help

here is was im trying to do: i have two types of enemies and would like to have when enemy 1 collides with enemy 2 then enemy 1 turn into a copy of enemy 2 and have all of enemy 2’s components

then when i shoot it enemy 2 i would like to have it turn into an enemy 1

I know i have to do an onCollisionEnter and the destroy object but i dont know where to go from there.

So i was wondering if there is a way to switch prefabs with an oncollision

Any help would be appreciated.

create a new enemy2 prefab and make it child of enemy1 prefab so when enemy1 prefab collide with enemy2 set false to enemy1 renderer and enanle the renderer of child_enemy2 and vice verse ,when enemy1 collide with bullet. :- enemy1 >enemy2var enemy1:Gameobject; private var child:GameObject; function Start() { child = enemy1.tranform.Find("enemy2"); child.renderer.enabled = false; } function OnCollisionEnter(other:Collision) { if(other.transform.name == "enemy2") { enemy1.renderer.enabled = false; child.renderer.enabled = true; } } i guess it works.

–

1 Answer

1

Or on collision save the position and rot in variables, spawn the new prefab and delete the old one