- Home /
How to rotate shader/texture?
Hi, I am building roads. I made a model road that I can stretch and manipulate in unity. I imported it, and put my road texture onto it and it is on sideways... is there an easy way to rotate the texture? Thanks
Please don't use the "Post Answer" button unless you're actually answering the question.
I'm not sure what you mean by your comment - textures don't have names.
Answer by aldonaletto · Sep 28, 2012 at 05:47 AM
You can modify material.mainTextureOffset:
var offset = Vector2.zero;
var speed: float = 0.5;
function Update(){
offset.y = (offset.y + speed * Time.deltaTime) % 1;
renderer.material.mainTextureOffset = offset;
}
This simple script should be attached to the road, and scrolls the texture in its Y direction. You can modify it to scroll in the X direction (replace y by x) or scroll in the reverse direction (use a negative speed). Notice that the offset is kept in modulo 1: the texture offset can't handle big numbers accordingly due to its limited precision.
Old thread, but some of us still stumble on these through Google. The question was about rotating the UV, not about moving it. From what I've gathered, it's done by adjusting the $$anonymous$$atrix of the Shader. Here are the best resources I found on this: http://forum.unity3d.com/threads/rotation-of-texture-uvs-directly-from-a-shader.150482/ http://forum.unity3d.com/threads/rotate-texture.19018/