UV mapping on mesh with tiling texture

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:


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._

Okay after a while trying different things, I decided to add plenty of print functions to figure out what was going on. After compiling the data and checking everything was right so I started to think it was something going on with the material and/or the texture itself.

Guess what, the texture wrap mode was set to clamp… So upon setting it to repeat everything was working fine.