Question by
LouanneDeltenre · Jan 09, 2021 at 03:06 PM ·
c#childdetach
Detach child of parent for each obj with a specific tag
Hi, I'm trying to figure ou a way to detach this white cube from his parent wich has became the floor when they collided.
Here's the way I attached them:
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "pion" )
{
other.transform.parent = this.transform;
Debug.Log("meet floor");
other.gameObject.GetComponent<Rigidbody>().useGravity = false;
other.gameObject.GetComponent<Rigidbody>().isKinematic = true;
}
}
But now I'm trying to find a way to clear the parent of each gameObject that has the tag "Pion" when I click on the black sphere at the top.
Made this code quickly on how I image it woud look like:
void OnMouseDown()
{
if (this.gameObject.tag == "Detach")
{
Debug.Log("touched");
GameObject[] Childrens;
Childrens = GameObject.FindGameObjectsWithTag("pion");
foreach (GameObject pion in Childrens)
{
Childrens.gameObject.GetComponent<Rigidbody>().useGravity = false;
Childrens.gameObject.GetComponent<Rigidbody>().useGravity = true;
}
}
}
capture.jpg
(21.5 kB)
Comment
Your answer
Follow this Question
Related Questions
NullReferenceException at adding a NetworkTransformChild component 1 Answer
How to find the transform position of another gameobject then move a gameobject to that position? 1 Answer
How to count child dynamically? 1 Answer
How to create a child object inside the parent (script) and assign independent variables? 0 Answers