- Home /
Question by
iamthecoolguy11 · Dec 31, 2013 at 07:06 PM ·
c#instantiatetransform
Simple instantiate a variable
I made a map editor script and im making it duplicate for some reason I cant get the instantiate to work correctly. Any way hears the duplicating part.
public Transform Editing;
void OnGUI()
{
if(GUI.Button(new Rect(400, 0, 50, 50), "Dup"))
{
Instantiate(Editing, transform.position, transform.rotation) as Transform;
}
}
Comment
Best Answer
Answer by Spinnernicholas · Dec 31, 2013 at 07:28 PM
You are instantiating a transform, which is only a component. You have to do it to the gameobject in order to copy everything.
Here's your code:
public Transform Editing;
void OnGUI()
{
if(GUI.Button(new Rect(400, 0, 50, 50), "Dup"))
{
Instantiate(Editing.gameObject, transform.position, transform.rotation);
}
}