I have check many posts about the topic but I still can seems to figure out how to achieve a good result.
I am trying to repeat a texture on a script generated mesh, at the moment I am able to set the texture properly if I set the tileAmount to 1. However, when I increase the tileAmount I get wierd results and I don’t understand why. I have tried many other solutions like using modulo with the texture width and height but it does not achieve what I am looking for.
Here’s what it looks like:
Code:
int tileAmount = 10;
Vector2[] uvs = new Vector2[vertices.Count];
for (int i = 0; i < vertices.Count; i ++) {
float percentX = Mathf.InverseLerp(-map.GetLength(0)/2*tileSize, map.GetLength(0)/2*tileSize, vertices*.x);*
_ float percentY = Mathf.InverseLerp(-map.GetLength(1)/2tileSize, map.GetLength(1)/2tileSize, vertices*.y);_
uvs = new Vector2(percentX, percentY) * tileAmount;
_ }
mesh.uv = uvs;*
In the sample above, map is a 2D array representing a cell then map.GetLength gives the width and height of the map._