- Home /
Question by
WhisperXD · Aug 08, 2018 at 03:31 PM ·
c#instantiatearray
How instantiate in array consecutive
Transform[] meatballSlots;
GameObject meatball;
private void Update()
{
foreach (Transform meatballSlot in meatballSlots)
{
if (Input.GetKeyDown(KeyCode.Space))
{
Instantiate(meatball, meatballSlot);
}
}
}
how can i to instantiate the "meatball" as child of "meatballSlot" consecutive, right now if i press space the "meatball" will instantiate on every "meatbalSlot", but i need instantiate will consecutive from 0, 1, 2, 3 and then when press each space
Comment
Hi, I didn’t understand what you are asking. Do you want to know how to instantiate the objects without pressing the space button every time? Then use Input.Get$$anonymous$$ey($$anonymous$$eyCode.Space)
Answer by khooroko · Aug 10, 2018 at 02:11 AM
Transform[] meatballSlots;
GameObject meatball;
int slotNum = 0;
private void Update() {
if (Input.GetKeyDown(KeyCode.Space)) {
Instantiate(meatball, meatballSlot[slotNum++]);
}
}
This will create the meatball at the next slot each time you press space. Is this what you're looking for?