Q
Q
qsecretp2018-11-20 13:44:56
C++ / C#
qsecretp, 2018-11-20 13:44:56

How to assign a Child to another Parent?

Unity.5.2.3. csharp.
You need to do this in the hierarchy through the script.
It turns out to move the object to the topmost Parent'u. Thus:

using UnityEngine;
using System.Collections;

public class ImpulseObject : MonoBehaviour {
  public GameObject inHands;
  public GameObject Slight;
        public GameObject Box;
        
        void Update () {
    if (Input.GetKeyDown(KeyCode.C))
    {
      print ("yes");
///////////////////////////////////////////////////////////////////////////////////
      Slight.transform.parent = inHands.transform;
///////////////////////////////////////////////////////////////////////////////////
      Box.GetComponent<Rigidbody2D>().isKinematic = true;
      //Box.transform.position = inHands.transform.position;
    }
  
  }
}

But we need the "Slight" object to move to "inHands" and become its Child.
I can't figure it out.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2018-11-20
@qsecretp

Use the SetParent method on transform.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question