I'm working on a Unity project where I need to draw on each face of a cube independently. However, when I draw on one face, the changes are reflected on all six faces of the cube simultaneously.
I've implemented a drawing functionality using a Drawer script. This script manages drawing points between the mouse clicks and interpolates them to create smooth lines. However, it seems that the interpolation logic is causing the drawn lines to appear on all faces of the cube.

Here's the relevant part of my Drawer script:
// Relevant code snippet from the Drawer script
private void SetPixelsBetweenDrawPoints()
{
while (drawPoints.Count > 1)
{
Vector2Int startPos = drawPoints.Dequeue();
Vector2Int endPos = drawPoints.Peek();
InterpolateDrawPositions(startPos, endPos);
}
}
IEnumerator DrawToCanvas()
{
while(true)
{
SetPixelsBetweenDrawPoints();
yield return new WaitForSeconds(drawInterval);
}
}
void InterpolateDrawPositions(Vector2Int startPos, Vector2Int endPos)
{
int dx = endPos.x - startPos.x;
int dy = endPos.y - startPos.y;
float xinc, yinc, x, y;
int steps = (Math.Abs(dx) > Math.Abs(dy)) ? Math.Abs(dx) : Math.Abs(dy);
xinc = ((float)dx / steps) * interpolationPixelCount;
yinc = ((float)dy / steps) * interpolationPixelCount;
x = startPos.x;
y = startPos.y;
for(int k=0; k < steps; k += interpolationPixelCount)
{
canvasDrawOrEraseAt((int)Math.Round(x), (int)Math.Round(y));
x += xinc;
y += yinc;
}
canvasDrawOrEraseAt(endPos.x, endPos.y);
}
void AddDrawPositions(Vector2Int newDrawPos)
{
drawPoints.Enqueue(newDrawPos);
}
I want to modify this script so that when I draw on one face of the cube, the changes are confined to that specific face only. How can I achieve this? Should I modify the interpolation logic or is there a better approach to handle drawing on individual faces of a cube?
Any insights or suggestions would be greatly appreciated. Thank you!
I think it's rather UV problem than script problem. you are using unity cube object that is UVed that way (each side have overlap with other sides). create a cube in a 3D program like Blender and import it and you will have something like this:
so when you are drawing on one side it will not show on other sides