- Home /
destroy object then instantiate a prefab at emptygameobject? please help
i already got my cube to be destroyed on TriggerEnter but how do i instantiate a object using a empty gameobject when the the cube is destroyed
so it should be like this... I touch the cube. cube destroys itself. a object instantiates at empty gameobject or different location(instantiates ONLY ONCE) any ideas?
Answer by henry96 · Oct 01, 2011 at 10:00 AM
All you need to do is instantiate it. First, you make a variable. Use this var for the position where the new object spawns. You might want to drag and drop that empty gameObject later. Here is an example of the code:
var objectToMake : Transform; //You will need to put prefab in this in the inspector
var spawnPos : Transform; //You will drag and drop on this
function OnTriggerEnter (col : Collider)
{
//When the cube is destroyed
Instantiate (objectToMake, spawnPos.position, spawnPos.rotation);
}
Hope this tip will help u! Cheers!
Your answer
Follow this Question
Related Questions
Having problems with destroying, instantiating 0 Answers
Instantiate Pre-fab clone altered on Instantiate 2 Answers
Scripts not on instantiated GameObjects? 1 Answer
How to Destroy a GameObject when the player looks away 1 Answer
when prefabs are spawned I want to touch them to destroy. help? 0 Answers