How do you make collision bounds using colour?

43402-maze-1.pngFirstly, can you even detect colour in unity ? It must be possible (through a add-on.) but it would take a tonne of coding to make a add-on. I would be suprised if this is not possible in Unity considering it is possible using BYOB (which uses javascript). You can download BYOB ( search in google)and look at what they use.
I know it would definitely be possible to make collision bounds using the coordinates of where the colour is. (complex collision bounds in gameobjects)

As you may be able to see, the image i am using attached below has no background and it is literally just the black part. Could i use this to create a complex collision bound ( maybe using child gameobjects)?

If you are making a add-on i only need the colour black in collision bounds( could make it easier to code).

The reason i want this is because i have about 80 different mazes that i need to create collision bounds for, and each is about 70 box colliders. so 70x80 is 5600 colliders and that is a awful lot of work. I will be needing only box colliders to work, and although there are some mazes with curved sides, i can change them if they arent right. Also, if the odd one or two box colliders are glitchy, it doesnt matter, i just want most of the work to be done.

Any help will be appreciated. Also, if you do post a script or add-on or something, then please can i have full permissions to use it in my app? Thanks.

Reading docs is always a good plan:

So, yes, you can read a colour from a texture. So, you could iterate over each pixel, and if it’s not white create a cube in 3d space.

I hope this fits your needs. The Colors are normalized rgb values so they range between 0 and 1.

public Texture2D image;//Just assign your image in the inspector.
private GameObject CubeManager

Color GetColor(int x, int y) { //Get the color at a specific coordinate
    x = Mathf.Clamp(x,0,image.width);
    y = Mathf.Clamp(y,0,image.height);
    return image.GetPixel(x,y);
}

void Start() {
    CubeManager = new GameObject(); //So your hierachy doesn't get flooded you make them a child of the CubeManager gameobject.
    CubeManager.name = "CubeManager";

    GenerateMap();
}

void GenerateMap() {
    for (int x = 0; x < image.width; x++) {
        for (int y = 0; y < image.width; y++) {
            GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
            cube.transform.parent = CubeManager.transform;
            cube.renderer.material.color = GetColor(x,y);
            if (GetColor(x,y) == Color.white) {
                cube.transform.position = new Vector3(x,0,y);
            } else {
                cube.transform.position = new Vector3(x,1,y);
            }
        }
    }
}

JS version:

public var image : Texture2D;//Just assign your image in the inspector.
 private var CubeManager : GameObject;
 
 function GetColor(x : int, y : int) { //Get the color at a specific coordinate
     x = Mathf.Clamp(x,0,image.width);
     y = Mathf.Clamp(y,0,image.height);
     return image.GetPixel(x,y);
 }
 
 function Start() {
     CubeManager = new GameObject(); //So your hierachy doesn't get flooded you make them a child of the CubeManager gameobject.
     CubeManager.name = "CubeManager";
 
     GenerateMap();
 }
 
 function GenerateMap() {
     for (var x : int = 0; x < image.width; x++) {
         for (var y : int = 0; y < image.width; y++) {
             var cube : GameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
             cube.transform.parent = CubeManager.transform;
             cube.renderer.material.color = GetColor(x,y);
             if (GetColor(x,y) == Color.white) {
                 cube.transform.position = new Vector3(x,0,y);
             } else {
                 cube.transform.position = new Vector3(x,1,y);
             }
         }
     }
 }

MakakWasTaken has made the following codes (and emailed them to me) that will work if you have a extremely fast computer/laptop. Unfortunately, it doesnt work for me right now but it will probably work once my new laptop arrives!!! Then i should be able to keep it in the game file so it is not in runtime!!!:

public var image : Texture2D;//Just assign your image in the inspector.
 private var CubeManager : GameObject;
 
 function GetColor(x : int, y : int) { //Get the color at a specific coordinate
     x = Mathf.Clamp(x,0,image.width);
     y = Mathf.Clamp(y,0,image.height);
     return image.GetPixel(x,y);
 }

 function Start() {
     CubeManager = new GameObject(); //So your hierachy doesn't get flooded you make them a child of the CubeManager gameobject.
     CubeManager.name = "CubeManager";
 
     GenerateMap();
     CubeManager.AddComponent(MeshCombiner);
 }
 
 function GenerateMap() {
     for (var x : int = 0; x < image.width; x++) {
         for (var y : int = 0; y < image.width; y++) {
             var cube : GameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
             cube.transform.parent = CubeManager.transform;
             cube.GetComponent.<Renderer>().material.color = GetColor(x,y);
             if (GetColor(x,y) == Color.white) {
                 cube.transform.position = new Vector3(x,0,y);
             } else {
                 cube.transform.position = new Vector3(x,1,y);
             }
         }
     }
 }

and:

import System.Collections.Generic; //Used for the list        

	function Start () {
		var meshFilters : MeshFilter[] = GetComponentsInChildren(MeshFilter);
		var combine : CombineInstance[] = new CombineInstance[meshFilters.Length];
		for (var i = 0; i < meshFilters.Length; i++){
			combine_.mesh = meshFilters*.sharedMesh;*_

combine_.transform = meshFilters*.transform.localToWorldMatrix;
meshFilters.gameObject.active = false;
}
transform.GetComponent.().mesh = new Mesh();
transform.GetComponent.().mesh.CombineMeshes(combine);
transform.gameObject.active = true;
}*_