- Home /
 
               Question by 
               zillion · Aug 14, 2012 at 07:51 PM · 
                javascriptinstantiatetransforminstantiation  
              
 
              Simple Instantiate gameObject problem
So, I have an enemy in my scene, and when he dies, I would like to destroy him, and then Instantiate a prefab, in the enemies exact position, rotation and scale. Barely EVER used Instantiate, so some assistance would be great! Already know how to destroy the enemy when he dies... but thats about it. Thanks in advance! PS. I only really work with Javascript...
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by OperationDogBird · Aug 14, 2012 at 07:59 PM
You can use instantiate from the enemy before you destroy him like this
On Enemy
 if(health<=0)
 {
     Instantiate(somePrefab,transform.position,transform.rotation);
     Destroy(gameObject);
 }
Answer by Mander · Aug 14, 2012 at 07:59 PM
 before u destroy ur object save its position and declare ur item in some variables
 
 var   itemPosition  = gameObject.transform.position;
 var   itemRotation  = gameObject.transform.rotation;
 var   itemRespawn : GameObject; <-- here ur prefab to spawn
 
 Destroy(gameObject);
 
 then instantiate the new gameObject
 
 var  item = Instantiate(itemRespawn , itemPosition, itemRotation);
hope this helps
Answer by zillion · Aug 15, 2012 at 05:13 AM
Both answers worked perfectly! Although, destroying the gameObject after instantiation worked well for my project. Thank you!
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                