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…
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);
}
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
Both answers worked perfectly!
Although, destroying the gameObject after instantiation worked well for my project.
Thank you!