How to align texture when comes to a corner

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:

uvs _= vertices*;*_

And here are two pictures, the first one is the wrong one. and the second is what i want.
![alt text][1]
pic 1
![alt text][2]
pic 2
The next two pictures may be more clear.
![alt text][3]
pic3 Look at the small green arrow,i wanna the texture align with it not the red one on its left.
![alt text][4]
Pic4 this is what i want
Hope that it’s clear.Any answer will be appreciate!
_[1]: http://en.gravatar.com/userimage/24104274/8d2c48ddf4b6c066ec4b0e1d18dca691.jpg?size=200*_
_
[2]: http://en.gravatar.com/userimage/24104274/6c00be89e3561d2f8b48eb3b97890202.jpg?size=200*_
_[3]: http://en.gravatar.com/userimage/24104274/9c3b10ffd7ad897e6c666bc904337773.jpg?size=200*_
_
[4]: http://en.gravatar.com/userimage/24104274/17d2b9a0aaeb134aac159f4dde907b4f.jpg?size=200*_

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:
uv-coordinates

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.

Extra info here: