- Home /
Duplicate a game object
Hi,
I try to make a platform game with obstacle like a little wall. When my character will enter a trigger zone, I want it to follow a path with a special animation. To do this, I create two sphere (pos1 and pos2) with my object littleWall (The character will join the first, then the second with Vector3.MoveTowards). When I launch my game, it works greats.
Now, I want to put a second littleWall on its path. I tried to duplicate it but it doesn't work. The first one works, but it stops at the second. I think it's because the objects have the same name (littleWall, pos1 and pos2).
I tried to use the 2 spheres with GameObject.Find, transform.Find, tranform.FindChild ...
This is my treeview :
littleWall
Trigger
Cube
pos1
pos2
How may I use this object multiple time.
Thanks for your reply
BearWarrior
Answer by jmgek · Jul 25, 2014 at 01:56 AM
Drag your little wall into your project and it will turn blue, when it is blue it becomes a prefab of the original parent. With that you can multiply" it as many times as you want.
Instantiate(ThePrefabYouWantToInstance, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
Thanks for reply.
I tried to create a Prefab and instantiate it, but it works like duplicate.
I solved my probleme by putting my gameobjects pos1 and pos2 in "Public" and dragging them to the script but I need to do this for each littleWall I create.
$$anonymous$$aybe that it comes from my scripts and links between my character and my gameObject.
I'll try to find a better solution in the futur.
Thanks you
BearWarrior
Your answer
