How to reset a child object to its parent
I am making a block buster type of game, and I am trying to get the ball to reset to the paddle after it goes off screen. I have the ball set as a child of the paddle initially so that they move together when the game starts, but I have a launch script for the ball that removes the ball as a child of the paddle so it can bounce around independently. The problem I am having is when the ball goes off screen (when a life would be lost), I can't get the ball to reset back to the paddle. One thought I had was to destroy the ball and paddle when the ball collides with the dead zone at the bottom of the screen (i placed a cube below the view of the camera to detect collision), and then Instantiate the entire Ball/Paddle game object. I am fairly new to using Unity and C# though, and have no clue how to achieve the desired result.
Answer by MrCrumbl3d · May 24, 2017 at 07:49 AM
try this code:
ball.transform.parent = paddle.transform;
put it in any function.
Your answer
![](https://koobas.hobune.stream/wayback/20220612122523im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Cannot convert 'UnityEngine.GameObject' to 'UnityEngine.Vector3' Why is this? 1 Answer
Script in C sharp collision when entered fires arrows at player 0 Answers
Playing specific sounds when an object is revealed 0 Answers
Best practices to select a group of gameObjects 1 Answer
Cycle through objects on mouse click 1 Answer