Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

change parent of gameobject in Unity3d

public GameObject Child;
public Transform NewParent;

// Sets "newParent" as the new parent of the child GameObject.
Child.transform.SetParent(NewParent);

// Removes parent, puts child into a top-level object in the hierarchy
Child.transform.SetParent(null);
Comment

how to get parent gameobject in unity

childObject.transform.parent.gameObject
Comment

set parent of gameobject unity

child.transform.SetParent(newParent);    
Comment

how to change a gameobject parent unity

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public GameObject player;

    //Invoked when a button is pressed.
    public void SetParent(GameObject newParent)
    {
        //Makes the GameObject "newParent" the parent of the GameObject "player".
        player.transform.parent = newParent.transform;

        //Display the parent's name in the console.
        Debug.Log("Player's Parent: " + player.transform.parent.name);

        // Check if the new parent has a parent GameObject.
        if (newParent.transform.parent != null)
        {
            //Display the name of the grand parent of the player.
            Debug.Log("Player's Grand parent: " + player.transform.parent.parent.name);
        }
    }

    public void DetachFromParent()
    {
        // Detaches the transform from its parent.
        transform.parent = null;
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# loop through list of objects 
Csharp :: add all elements in a list c# 
Csharp :: c# date format 
Csharp :: fade image out unity 
Csharp :: unity exception 
Csharp :: how to pass string value to enum in c# 
Csharp :: add row count devepxress report 
Csharp :: unity play sound effect 
Csharp :: function on animation end unity 
Csharp :: c# add multiple items to list 
Csharp :: color unity 
Csharp :: c# regex match 
Csharp :: how to check that string has only alphabet in c# 
Csharp :: c# double to int 
Csharp :: update multiple records with entity framework 
Csharp :: c# swtich 
Csharp :: string to datetime c# 
Csharp :: c# remove first line from textbox 
Csharp :: c# decimal vs double 
Csharp :: unity custom editor 
Csharp :: c# create tasks and wait all 
Csharp :: unity call function on update once per second 
Csharp :: c# unescape string 
Csharp :: c# add button to messagebox 
Csharp :: an existing connection was forcibly closed by the remote host. .net core 
Csharp :: Dyanmically create datatable in c# 
Csharp :: how to acivate a game object unity 
Csharp :: c# switch case greater than 
Csharp :: unity toint 
Csharp :: c# how to crete array 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =