- Home /
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
eprivate 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.nemy2`var enemy1:Gameobject;
Answer by KMKxJOEY1 · Mar 28, 2013 at 04:41 AM
Or on collision save the position and rot in variables, spawn the new prefab and delete the old one
Your answer
Follow this Question
Related Questions
NavMesh and WaveSpawner dont work together! 2 Answers
enemy ai going to player 2 Answers
2d enemy prefab (enemy movement and instantiate) 1 Answer
Help with Enemy AI 1 Answer