Instantiate multiple objects from a var

Hi, I am trying to sort out my random loot generator.

I have a var that sets the number of gold coins to produce, and I am creating them from a prefab using

            Instantiate(goldKeyPrefab, transform.position, transform.rotation);

My question is, how can I create multiple of the above prefab based on the variable amount?

I would be very grateful if someone could help me out with some c# code :slight_smile:

Instantiate the coins in a loop with your var as the loop condition:

var numCoins = 10;//for example
for (int count = 0; count < numCoins; count++)
{
Instantiate(goldKeyPrefab, transform.position, transform.rotation);
}

This is where a for loop comes in handy.

for (int i = 0, i < noOfGoldToMake, i++){
    // Do whatever you need here
}

Thank you all, that really helped me out thanks!