UV issues - help!

Hi guys, I’ve generated an object at run time and having issues with texturing it, down to UV’s I believe. I’m using the code below to generate the UV"s

	private void SetTextureCoordinates()
	{
	  Vector2[] uvs = new Vector2[newVertices.Length];
        int i = 0;
        while (i < uvs.Length) {
            uvs <em>= new Vector2(newVertices_.x, newVertices*.z);*_</em>

i++;
}

mesh.uv = uvs;
}
But the results I’m getting are odd (see attached screen shot). Anyone any ideas where I"m going wrong?
Thanks[11820-uv.jpg|11820]

UV Coordinates are set from 0 to 1 across the whole area you want the texture to apply to. As your code is now, you are setting the UV coordinates in full steps based on the physical location of the vertices in space. As a result, you are getting a ton of tiling because the texture thinks that you want it to display fully in each of those increments.

I’m not sure how you want the tiling to work, but let’s assume you wanted a single texture to apply across an entire mesh defined by your vertices. In this case, you would want to set the UVs as you go across the mesh based on the % of the total mesh. Something like:

for (int z = 0; z < maxZ; z++)
  {
  for (int x = 0; x < maxX; x++)
    {
    uvs *= new Vector2(x / (maxX - 1.0f), z / (maxZ - 1.0f));*

i++;
}
}
This probably won’t work for what you are trying to do, but I am trying to get the idea across. In this case, my UV values are going from 0.0 all the way up to 1.0 in both X and Z directions as you go across the entire mesh. If you wanted to tile differently, you can modify the looping so that the 0.0-1.0 range is repeated in smaller chunks.