unity create a child object code example
Example: unity create a child object
// spawns object
objToSpawn = new GameObject("Start");
// add Components
objToSpawn.AddComponent();
objToSpawn.AddComponent();
objToSpawn.AddComponent();
objToSpawn.AddComponent();
// sets the obj's parent to the obj that the script is applied to
objToSpawn.transform.SetParent(this.transform);