Примерно так?
using UnityEngine;
using System.Collections;
public class main : MonoBehaviour
{
public int countBlock;
// Use this for initialization
void Start()
{
int i;
for (i = 0; i < countBlock; i++)
{
var go = GameObject.CreatePrimitive(PrimitiveType.Cube);
go.name = "box" + i.ToString();
go.transform.position = new Vector3(Random.value * 40 - 20, 1, Random.value * 40 - 20);
go.renderer.material.color = new Color(Random.value, Random.value, Random.value);
}
}
// Update is called once per frame
void Update()
{
}
}