Problem with object generation script?

Hello, I made a script to generate a certain amount of objects in random places around the game map, but after realizing that my code was disguising (it involved twenty if-statements rather than two foreach statements) I decided it was time to fix it, but I am not really too sure on how to sync the number of objects left to be generated with the type of object that needs to be generated. I tried to sync it by running a foreach-statement inside of a foreach-statement, but I don’t think Unity likes that very much.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EcoGeneraterScript : MonoBehaviour {

	public GameObject Map;
	public GameObject[] GeneratedObjects;
	public int[] NumberofObjectsToGenerate;

	void Update () {
		foreach (int NumberofObjectToGenerate in NumberofObjectsToGenerate) {
			foreach (GameObject GeneratedGameObject in GeneratedObjects) {
				if (NumberofObjectToGenerate > 0) {
					Instantiate (GeneratedGameObject, new Vector3 (Random.Range (0, Map.transform.localScale.x), 0, Random.Range(0, Map.transform.localScale.y)), Quaternion.identity);
					NumberofObjectToGenerate += -1;

Error that I am getting: Assets/Scripts/EcoGeneraterScript.cs(16,6): error CS1656: Cannot assign to NumberofObjectToGenerate' because it is a foreach iteration variable’

Does this help? Using for instead of foreach.

for ( int i = 0; i < NumberofObjectsToGenerate.Length; i++ ) {
	foreach ( GameObject GeneratedGameObject in GeneratedObjects ) {
		if ( NumberofObjectsToGenerate[ i ] > 0 ) {
				new Vector3(
					Random.Range( 0, Map.transform.localScale.x ),
					Random.Range( 0, Map.transform.localScale.y )
			NumberofObjectsToGenerate[ i ] -= 1;

Other thing. There’s special reason why are you doing this on Update instead of Start?