Unity Beginners - How to Parent/Un-parent Objects in runtime

preview_player
Показать описание
Learn when we need to parent objects in run-time and how to go about it? In this video, we will see how to use 'SetParent' code with an example. As usual, the logic in this video has been kept relatively simple. Have fun :)

If you like the content of this channel please do subscribe and like the video. All comments are welcomed!
See all my tutorials on Unity at:

Want to connect instantly? reach me at -
Рекомендации по теме
Комментарии
Автор

Thanks a lot, I was trying to create a Grab / Throw system and this helped a lot!

gengisbohx_
Автор

Exactly what I needed, thanks!!! For those who want to use this in 3D here's my slightly modified code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MovingPlatform : MonoBehaviour
{
public bool isOnMovingPlatform = false;
public GameObject MyPlayer;

void Update()
{
if (isOnMovingPlatform)
{

}
else
{
null);
}
}
void OnTriggerEnter(Collider other)

{
if

{
isOnMovingPlatform = true;
}

}
void OnTriggerExit(Collider other)
{
if
{
isOnMovingPlatform = false;
}

}

}

starchaser
Автор

please please tell me in unity 3d how can i make camera to be a child of the car when it go on a collider and when i drop from it it gets unparented please tell me sir i come this far for my game but now i am stuck on this problem

MysteryUnclear
Автор

it makes my character slow is there a way i can fix this?

merens
Автор

Hi
im using 3D objects,
and for some reason, in my C# file, I can't find the OnCollision functions..
any ideas?

YuvalAmiel
Автор

Oh my god i needed this thank you man so much!

viksingg
Автор

Thankz bro 😍😍 well define 😉😉
Subscribed

mhdrxshid
Автор

Thankyou so much. It worked in my FPS game with some minor modifications. Just " OnCollisionEnter(Collision other) "

GandBeckz
Автор

With one Platform, it worked, but everytime i have two Platforms, my Player can stick on only one of them. And it is always the one I placed last. Do you know, how to fix this?

ninolorenz
Автор

Would it be possible to set the "public gameObject" to instead use a list of all gameObjects that have a specific tag?

Im making a game where the player grad and drops gameObjects to/from other tabs (UI panels that can be closed/opened), and would love to be able to have multiple items (multiple types) that can all be drag+dropped in, then have them set to the parent "slot".

(I have the drag drop sorted, just need to set the parents, its why i clicked this vid to find out how xD. The script here is almost exactly what i need, but I'll back up my scripts and experiment :P lol)

Duros
Автор

awesome, thank you for making this tutorial, I now can successfully make a inventory and seating system in my vr game.

CDerek
Автор

This is works nice. I just subscribed :D

Ialsodowatchyoutube
Автор

Thank you! This video is very helpfull! 🙂👍

vladimirkraft
Автор

This is awesome, thank you very much!

LorenaTriffoni
Автор

For some reason this only works on one platform
It won't work on a duplicated platform

primoscarab
Автор

I've tried doing this but it isn't working for me. I'm doing it the other way around though. when the player touches an object it makes the object the child of the player. But I never want it to let go, thats why i got rid of the OnCollisionExit();

This is my code:
public bool isOnMovingPlatform = false;

public GameObject MyPlayer;

void Update()
{
if (isOnMovingPlatform)
{

}
else
{
transform.SetParent(null);
}
}

private void other)
{
if
{
isOnMovingPlatform = true;

}
}


The weird part about it is that it all works. The object becomes the child of the player. but it doesn't stay with it. it just reacts normaly.

mr_mcgilicuty
Автор

helped me to figure out how I could get the player to grab some 3d rope 😁

OxisTech
Автор

nice way of explaining but please decrease background music level

mohsen
Автор

bruh lol. you example are exectly the problem I was looking for a solution

ABYZA
Автор

Horrible Choice of Audio man. The backround music has this unbareble locust like sound, I advice to change that for future vids.

zoren