- Home /
How to make parent for my prefabs using script?
I hv 10 cards prefabs and i want to intantiate all of them in scene under a group.. Deck is the parent(i want it to be), and card shud be children...so when i move my deck card will be moved ...so the problem is when i use intantiate every card is coming on each other and all mixed up they r now children but all mixed up...
or other way all card are on scene on the right position while game but they do not hv parent (deck)... is there any way that i can put them in deck while gameplay using scrip... (part of scripting)
transform.localPosition.z=height
clone=Instantiate(card, transform.position, transform.rotation)
cloned=clone.transform
cloned.parent = deck
height = height + 0.002
Answer by Jesse Anders · Apr 03, 2011 at 06:33 AM
The question is a little unclear, but I notice you're assigning 'height' to 'localPosition', but then using 'position' when you create the object. If all the cards are being instantiated at exactly the same position, that might be the reason.
yes if i m making the clone child of deck so its instatiating in the same position ...
is there any way to select all cards i hv taged with "Card" while gameplay using scrip after instatiating them...if there it will also work for me ...
You can use GameObject.FindGameObjectsWithTag() to find all active game objects in a scene with the specified tag.