- Home /
How to instantiate within GameObject
Whenever I instantiate my main player object from a prefab to the scene, all the GUIs attached to the scripts which are applied to the player don't seem to work. I had the idea of applying all the scripts to another GameObject in the scene, then instantiating the player within the GameObject. How would I do this? and is there an easier solution? Im using C# thanks
public class instantiate : $$anonymous$$onoBehaviour {
public Transform trike;
void Start() {
Instantiate(trike);
}
}
Then I attached my player from the prefab in the little space in the inspector
Not that it should matter? But try
public GameObject trike;
and see how that works
Answer by a1exi8 · Mar 19, 2013 at 02:26 AM
Solved it with the following code:
public GameObject trike;
public GameObject trike2;
public GameObject test;
GameObject obj;
void Start() {
obj = (GameObject) Instantiate(trike, test.transform.position, test.transform.rotation);
obj.transform.parent = test.transform;
obj = (GameObject) Instantiate(trike2, test.transform.position, test.transform.rotation);
obj.transform.parent = test.transform;
}
}
Your answer
Follow this Question
Related Questions
How to Reference Player when Instantiating Prefab 1 Answer
Cannot destroy child object in prefab- Error 1 Answer
gameObject are not referenced 2 Answers
Instantiating a prefab and setting its variables 2 Answers
Instantiate A Prefab 1 Answer