I draw a rect tunnel using Mesh, It all works well. What is the problem is:How can i align its texture with the tunnel.For example, when the tunnel turns off, the texture i assigned does turn at all by using codes like this:
Here’s an idea, its not great because it will cause some stretching, but I would map it so that the floor is in a straight line on your uv map. Something like:
then when the path turns, the uvs will rotate in that direction. If you’re doing it procedurally. If you’re doing it manually, then your can definitely do a better job than this.
Let’s give it a try. This is the correct way of doing it, and it completely depends on you uv-coordinates. As you describe, you only set your uv-coordinates to the vertex position in real-world. This means, that you will get uv-coordinates like (100,350,1). So what happens if you go around the corner? Nothing, because you do not catch that in your coordinates.
Your coords should go like this:
You see that the image actually goes around the corner. uv-coordinates are not numbers going from position to position. They have their own values. Normally, a quad or a complete mesh goes from (0,0) to (1,1), but you can also let them continue past that number. If you do so, like in the above example, you need to assign your texture to be repeated (or mirror repeated) and not clamped.
So during your for-loop, you need to assign values that correspond to these values in the example.