How to set an object to be a child of another using c#
I have a game that includes an elevator, but when the player gets on the elevator, and the animation triggers, it is very glitchy and the player is sometimes shot off the elevator. I want to make the player a child of the elevator once it touches it so it can go up and down smoothly. All help appreciated !!
Comment
Answer by EthanRushbrook2 · Jun 17, 2018 at 09:39 PM
You can do:
public GameObject child;
public GameObject parent;
//assign these in the inspector
void SetParent () {
child.transform.parent.SetParent(parent);
//that should work
}