enter image description here

I've been searched about how to make these fruit to move as the basket movement if it collided with it, and I've been found that if I want to perform this I've to let these fruit to be a child to the basket game object .. for example :

banana.transform.parent = basket.transform;

banana and basket each of them of type "GameObject" ...

BUT unfortunately this way didn't work !! and I don't know why ??

So now I need to know if it is possible to destroy the banana if a collision with the basket happened and instantiate a new banana in the basket as a child at run time ?!!

I need to try this stupid way because I've tried all the other ways and nothing worked :(

  • \$\begingroup\$ In what way did it not work? Even though the fruit is a child of the basket, it doesn't remove the physics properties of the fruit. If you want the fruit to stay in place after contact with the basket, disable its physics component. \$\endgroup\$
    – House
    Commented Oct 19, 2013 at 18:05
  • \$\begingroup\$ @Byte56:for example : the fruit are moving as the same as the monkey before falling down into basket ... and if I let the monkey without movement to the left or to the right (horizontal) and wait for the fruit to collide with the basket it don't stay in place and complete it's down movement ! \$\endgroup\$
    – Akari
    Commented Oct 19, 2013 at 19:11
  • \$\begingroup\$ How are you making the bananas fall? If you're using physics, they will continue to fall regardless of whether they're parented to the basket or not, as @Byte56 said. \$\endgroup\$
    – raybarrera
    Commented Oct 20, 2013 at 19:51

1 Answer 1


banana.transform.parent = basket.transform;

should work. If it doesn't, what happens?

This depends on how you are moving the fruits in the first place. You'll need to disable the script, or at least the function, that is making the fruit move down. Once you set the parent the fruit will still move independent of the parent unless you explicitly state to move in a relative way. Otherwise, the fruit will still be moving downwards even when it's parented unless you remove the script that is causing the downward movement.

I think the best approach would be to have a funciton like doMove(bool true){if true //Stuff} and then change the variable when the fruit collide with the basket.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .