Randomly Generate/Place map peices

Hi im in the middle of developing a small arcade tabletop tank shooter called toybox tanks and i would love to be able to have the maps randomly generated but im not sure where to start id like them in the style of this quick demo that i made can you guys please throw some info my way

https://b192ddecf4b575d31d27b954ade6e1d7b1c4ab83.googledrive.com/host/0B43i3Vbj6l21STdZMVB2Q214V00/New%20folder.html

So expanding on my comments above, here is a bit of code that builds blocks based on a texture created in Photoshop.

using UnityEngine;
using System.Collections;

[System.Serializable]
public struct Entry {
	public GameObject prefab;
	public Color color;
}

public class Builder : MonoBehaviour {

	public int levelCount = 2;
	public Entry[] entries;
	
	void Start () {
		StartCoroutine (ProcessImage ());
	}
	
	IEnumerator ProcessImage() {
		
		Texture2D tex = Resources.Load ("Level"+Random.Range(0,levelCount)) as Texture2D;
		
		Vector3 v3Start = new Vector3(-tex.width / 2.0f, 0.0f, -tex.height / 2.0f);
		
		Color32[] arcolors = tex.GetPixels32();
		for (int i = 0; i < tex.width; i++) {
			for (int j = 0; j < tex.height; j++) {
				Vector3 v3Pos = new Vector3(v3Start.x + i, 0.0f, v3Start.z + j);
				Color color = arcolors[i + tex.width * j];
				if (ColorSqrDistance(Color.white, color) > 0.1f) {
					PlaceItem(v3Pos,color);
				}
			}
			yield return 0;
		}
		Resources.UnloadAsset(tex);
		tex = null;
	}
	
	void PlaceItem(Vector3 v3Pos, Color color) {
		for (int i = 0; i < entries.Length; i++) {
			if (ColorSqrDistance(entries*.color, color) < 0.1f) {*

_ Transform t = (Instantiate(entries*.prefab) as GameObject).transform;_
_
t.position = v3Pos;_
_
t.parent = transform;_
_
return;_
_
}_
_
}_
_
Debug.Log (“Error, color not found”); // Should never get here if texturd is authored correctly*_
* }*

* float ColorSqrDistance(Color c1, Color c2) {*
_ return ((c2.r - c1.r) * (c2.r - c1.r) + (c2.b - c1.b) * (c2.b - c1.b) + (c2.g - c1.g) * (c2.g - c1.g));
* }*
}
This is how the entries in the Entries array are setup in the Inspector:
[33042-builder2.png|33042]*

Note entries in the array associate prefabs with the colors. The sample prefabs I worked with are blocks, windows in two directions, rollers in two directions, and a sphere. The images to be process into a level need to be in the Assets > Resources directory (as currently implemented).
[33043-builder.png|33043]_
The top part of this image is the result when the app is run. The bottom left is how the input image looks as I’m authoring in Photoshop (i.e. zoomed to 1800%). The bottom right (inside the circle) is what the input image looks like when scaled to 100%.
Note nothing limits the behavior of the prefabs other than (as currently implemented) they must have width/depth of (1,1). For example, the sphere prefabs have a Rigidbody and a script. After they are placed, the script lifts them up and gives them some random force so they roll around a bit. So for example, you could create a prefab that is moving in some way, or explodes when touched). And all you need is to associate it with a color to be able to author it in the image.
Here is a link to the sample project I used to verify things worked:
_
[Welcome laughingloops.com - Hostmonster.com][3]_
And finally a reference to another answer where I used a similar technique for a different kind of building:
_
[Spawn objects using a texture - Unity Answers][4]_
_

_*
_[3]: http://www.laughingloops.com/Builder.unitypackage*_
_
[4]: http://answers.unity3d.com/questions/411593/spawn-objects-using-a-texture.html*_

Im no coding expert but you could use math.random() in javascript and have a range of decimals set for each map. it returns a random number between 0 and 1 (ie. if math.random() equals 0-0.1, display this map) just an idea, hope you find a solution.

So @robertbu’s solution is very good, but its not true random level generation. Random level generation is still beyond me. But there was a very good discussion on it at Unite this year.

BTW: Favouriting this question to steal @robertbu’s code for level generation in my own game