I modified this code to get what I need. I modified it and this is my final code:
Vector2[] uvb;
Vector2[] uva = new Vector2[] { new Vector2(0, 0), new Vector2(1, 1), new Vector2(1, 0), new Vector2(0, 1) };
float w, h, left, bottom, posX, posY;
Rect uv = new Rect();
MeshFilter filter;
for (int i=0; i<rects.Count; i++)
{
AdaptedRect rect = rects[i];
w = rect.width * blockWidth;
h = rect.height * blockHeight;
left = rect.left * blockWidth;
bottom = rect.bottom * blockHeight;
posX = groundRect.left + left + w / 2;
posY = groundRect.bottom + bottom + h / 2;
squareBlocksPool[i].transform.position = new Vector3(posX, posY, squareBlocksPosZ);
squareBlocksPool[i].transform.localScale = new Vector3(w, h, blockThickness);
squareBlocksPool[i].SetActive(true);
// ATLASING
uv.x = 0;
uv.y = 0;
uv.width = rect.width / columns;
uv.height = rect.height / rows;
filter = (MeshFilter)squareBlocksPool[i].GetComponent<MeshFilter>();
uvb = new Vector2[uva.Length];
for (int p = 0; p < uva.Length; p++)
{
uvb[p] = new Vector2(uva[p].x * uv.width + uv.x, uva[p].y * uv.height + uv.y);
filter.mesh.uv = uvb;
}
}
System.Drawing
perhaps). Although even if you provide that info, I'm not sure your question contains enough information about what you are trying to achieve to give you a good answer. Try expanding it. \$\endgroup\$