这听起来很简单:
public enum CubeType
{
white,
yellow,
blue,
red,
green,
orange
}
private readonly IReadOnlyDictionary<CubeType, Color> colors = new Dictionary<CubeType, Color>
{
{CubeType.white, Color.white},
{CubeType.yellow, Color.yellow},
{CubeType.blue, Color.blue},
{CubeType.red, Color.red},
{CubeType.green, Color.green},
{CubeType.orange, Color.orange},
}
// Size/Expands of one cube tile
public float cubeSize = 1f;
public GameObject prefab;
// Amount of layers/dimensions e.g. 3x3
public int dimensions = 3;
public void SpawnCube(int x, int y, int z, CubeType type)
{
var cube = Instantiate (prefab, new (Vector3(x,y,z) - Vector3.one * dimensions / 2f) * cubeSize, Quaternion.identity);
// Or whatever you want to do with the type
cube.GetComponent<Renderer>().material.color = colors[type];
}