Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

unity create a child object

		// spawns object
        objToSpawn = new GameObject("Start");

        // add Components
        objToSpawn.AddComponent<Rigidbody>();
        objToSpawn.AddComponent<MeshFilter>();
        objToSpawn.AddComponent<BoxCollider>();
        objToSpawn.AddComponent<MeshRenderer>();

        // sets the obj's parent to the obj that the script is applied to
        objToSpawn.transform.SetParent(this.transform);
 
PREVIOUS NEXT
Tagged: #unity #create #child #object
ADD COMMENT
Topic
Name
5+1 =