- Home /
Instantiate And GetComponent
Hello,, i want to ask question about instantiate and GetComponent
public GameObject meatball;
GameObject meatballAfterInstantiate; //filled with meatballs (Clone) that have been instantiated
private void Start()
{
Instantiate(meatball);
// how to meatballAfterInstantiate
// Is it filled with meatball(Clone) that have been instantiated ??
}
so for example I made 2 object that will Instantiate "meatball", then I want to "meatballAfterInstantiate" filled with "meatball(Clone)" which has been Instantiate from each object that Instantiate them, so "meatball (Clone)" fill "meatballAfterInstantiate" from each object Instantiate them, sorry the question is a bit confusing, I also confused way to ask and sorry for my english
Answer by cryingwolf85 · Aug 03, 2018 at 05:42 PM
Too many people are sorry for their english on these forums. Don't be, the fact that you can speak multiple languages is impressive on its own.
It sounds like you just want to set "meatballAfterInstantiate" to a newly created meatball game object, with the result being a 'meatball' and not a game object. I've made some modifications to the code you posted:
public Meatball meatball;
private Meatball meatballAfterInstantiate;
private void Start()
{
meatballAfterInstantiate = Instantiate(meatball);
// meatballAfterInstantiate should now be your new meatball, and you can do with it as you wish.
// If you want to spawn it with a position:
Vector3 someRandomPosition = new Vector3(1,2,3);
meatballAfterInstantiate = Instantiate(meatball, someRandomPosition, Quaternion.identity);
}
Hope that helps.
No problem! Good luck with your meatballs. Lol