# How would I add a random enemy amount?

Hello, I’m making a 2D endless jumping game where you jump up a platform and it can have an enemy. I want there to be a chance for there to be two enemies on that one platform instead of just one, like on other ones. I’d also want there to be a chance that there’s zero enemies on a platform. I had a float called “enemyCount” too and it was random between 0 and 2 but I couldn’t really figure out how to implement that. I’ll have the code down below. I obviously won’t ask anyone to code my stuff for me. I just don’t really know where to start.

``````    public GameObject Ground;
public int groundCount;
public GameObject Enemy;

// Start is called before the first frame update
void Start()
{
groundCount = Random.Range(100, 300);
for (int i = 0; i < groundCount; i++)
{
Vector2 spawnPosition= new Vector2(0, i * 10);
Vector2 EnemyPosition = new Vector2(Random.Range(-10f, 14f), i * 11);
Instantiate(Ground, spawnPosition, Quaternion.identity);
Instantiate(Enemy, EnemyPosition, Quaternion.identity);

}
}
``````

Hi. You could put enemyCount inside the for loop, then instantiate the enemy inside another loop. e.g.

``````for (int i = 0; i < groundCount; i++)
{
int enemyCount = Random.Range(0, 2);
Vector2 spawnPosition= new Vector2(0, i * 10);
Vector2 EnemyPosition = new Vector2(Random.Range(-10f, 14f), i * 11);
Instantiate(Ground, spawnPosition, Quaternion.identity);
for (int i = 0; i < enemyCount; i++) {
// Instantiate enemy here
}
}
``````

Hope this helps.