x


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
more ▼

asked Apr 02 '11 at 08:35 PM

Craxter gravatar image

Craxter
17 4 4 7

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Apr 03 '11 at 06:33 AM

Jesse Anders gravatar image

Jesse Anders
7.3k 7 17 48

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 ...

Apr 05 '11 at 10:01 AM Craxter

You can use GameObject.FindGameObjectsWithTag() to find all active game objects in a scene with the specified tag.

Apr 05 '11 at 11:48 AM Jesse Anders
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5071
x1670
x420
x409
x70

asked: Apr 02 '11 at 08:35 PM

Seen: 1373 times

Last Updated: Apr 02 '11 at 08:35 PM