- Home /
what to put in vector3 when instantiating Gameobject at Gameobject?
I have a prefab that is an empty Gameobject and a Gameobject that is acting as an enemy. I'm trying to get the enemy Gameobject to spawn at the empty Gameobject. I want to be able to move the empty Gameobject anywhere and the enemy Gameobject would still spawn there without me having to change the code. Can I even do this with instantiate or do I need to use so etching else? If I can. Use instantiate what do I put in the vector3 spot?
Answer by aldonaletto · Oct 17, 2012 at 01:50 PM
The game object position is given by transform.position. If the empty object instantiates the prefab at its position (and with the same rotation), use this:
Instantiate(prefab, transform.position, transform.rotation);
Answer by Montraydavis · Oct 17, 2012 at 01:47 PM
Well, you don't typically Instantiate inside of a prefab, but rather Instantiate a new instance of the prefab it's self.
It's very easy.
var MyGameObject ;
MyGameObject = Instantiate ( objectBeingStantiated, transform.position, transform.rotation ) ;
You can then move it around just as you move everything else in the game .
Or Perhaps, are you trying to copy the contents of prefab1 to prefab2 ? ( which is basically the exact same )
Your answer
Follow this Question
Related Questions
Rotating a Vector3 in Instantiation 1 Answer
Instantiate after collision 2 Answers
XBox Controller Angle of Fire Incorrect 0 Answers
Add 0.5f to Vector.Right on next instantiated object ? 1 Answer
Instantiate object as a child of other instantiate 2 Answers