- Home /
Generate 2 gameobjects as child
Hi ,
I was wondering if its possible to generate 2 gameobjects as child when i attach a specific script in EDITOR MODE ?
If yes ,then plz tell me how because i have no clue about this.
Answer by PhoenixBlackReal · May 09, 2015 at 10:33 AM
Check out [ExecuteInEditMode] and the general approach of having scripts to work in Edit Mode.
To child an object, use the transform of the parent:
child_object.transform.parent = parent_object.transform;
To instantiate an object, check out the Instantiate class.
I'm writing "on the go" so I can't really drop the entire code from memory right now, even less do I want to make a syntax mistake which might be of trouble later. But this might be some start to get you moving and experimenting on your own. Good luck!
@PhoenixBlackReal : [ExecuteInEdit$$anonymous$$ode] Works fine ..... the game object pops right when i add script to any gameobject . But when i run the game it again create the same objects (Since the code is in Start). How to stop that ?
[ExecuteInEdit$$anonymous$$ode]
public class $$anonymous$$ovingPlatform : $$anonymous$$onoBehaviour {
GameObject EndPoints;
// Use this for initialization
void Start () {
if (EndPoints == null) //Doesnt Work
{
EndPoints = new GameObject("EndPoints"); //This runs twice (once in editor and then in run)
EndPoints.transform.parent = this.transform;
}
}
Answer by Basen · May 09, 2015 at 10:29 AM
GameObject t = (GameObject) Instantiate(yourobjectname, objectposition, object rotation);
t.transform.parent = parentname.transform;
Your answer
Follow this Question
Related Questions
in-editor cloning of game objects 1 Answer
Programatically instantiating GameObjects to the editor (not during gameplay) 2 Answers
Editor Script: Linking GameObjects to public script variables resets when playing. 1 Answer
PrefabUtility.InstantiatePrefab not preserving prefab connection 0 Answers
Weird bug when dragging object onto EditorGUILayout.ObjectField 0 Answers