- Home /
how to scroll texture on a plane
Hi there,
I have a simple question:
I would like to scroll a texture from right to left on a plane.
How can I do this ?
I was thinking of making an array with different texture and render one after the other. It would be nice to always have texture on that plane to make it look like skyscrapper in NY.
Please gimme a hand
THX
Answer by AlucardJay · Jul 11, 2012 at 05:07 AM
This is an example using SetTextureOffset
:
http://docs.unity3d.com/Documentation/ScriptReference/Material.SetTextureOffset.html
This is an example for swapping the UV's of the mesh verts.
#pragma strict
public var scrollSpeed : float = 0.1;
private var mesh : Mesh;
function Start()
{
mesh = this.transform.GetComponent(MeshFilter).mesh;
}
function Update()
{
SwapUVs();
}
function SwapUVs()
{
var uvSwap : Vector2[] = mesh.uv;
for (var b:int = 0; b < uvSwap.length; b ++)
{
uvSwap[b] += Vector2( scrollSpeed * Time.deltaTime, 0 );
}
mesh.uv = uvSwap;
}
This is the most powerful answer here, as it changes the mesh's UV map, letting you do more than just fiddle with the offset. (Thought fiddling with the offset might have worked for the original question, assu$$anonymous$$g the UV map was set up properly.)
Answer by NoReturnPro · Jan 19, 2013 at 02:05 AM
here i found this
//scroll main texture based on time
var scrollSpeed : float = .5;
var offset : float;
var rotate : float;
function Update (){
offset+= (Time.deltaTime*scrollSpeed)/10.0;
renderer.material.SetTextureOffset ("_MainTex", Vector2(offset,0));
}
now this works going from left to right but if anyone can tell me how to change which direction it scrolls id really appreciate it. I'm trying to make a water fall but its falling to the left not down lol
Change the line to the following:
renderer.material.SetTextureOffset ("_$$anonymous$$ainTex", Vector2(0,-offset));
this is the best example, it is pretty much from here:http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$aterial.SetTextureOffset.html
however what you want to know is how to scroll different directions, that would be achieved by using the Vector 2, you would put values in the place the 0 is for the other axis, use negatives to scroll backwards, or do some further reading and incorporate a angle to vector conversion (not strictly required)
okay i needed one for myself, this is how i done it:
public class ScrollTexture : $$anonymous$$onoBehaviour {
public Vector2 Scroll = new Vector2 (0.05f , 0.05f);
Vector2 Offset = new Vector2 (0f, 0f);
void Update () {
Offset += Scroll * Time.deltaTime;
renderer.material.SetTextureOffset ("_$$anonymous$$ainTex", Offset);
}
}
i think that personally is the most simple way to get any direction
Answer by webster · Jul 11, 2012 at 01:13 AM
If you mean tile, like bricks/windows on a building, play with the Tiling numbers on the material. If you mean animated, then animate the offsets on the material.
What I mean is I want texture like commercial, pub scrolling on a buildingface to make it look like it is advertisement.
That's called a marquis, you probably mean the one in Times Square. Animate the X (or Y) number on the material that has your texture. You can do that with a script or the animation editor
O$$anonymous$$ good, but how can i make it move again and again, need some help for ths script, thank you
Use the animation editor. Put the texture on a material, put the material on a Plane. Select the plane, Ctrl-6, find the material's X offset, have it go from 0 to 1, and set to 'loop'. Play. that's all
Answer by MrDude · Apr 16, 2014 at 03:14 PM
unfortunately, that code no longer works in 4.3. Now it just moves the texture till it's off the model and then shows nothing any more... :(
It's like Unity no longer uses texture space 0..1 but 0..infinity. If you offset the texture by 1 or more, you get nothing...
Is your texture set to Repeat or Clamp ? (make sure it's repeat)
That was my problem, I needed to set it to repeat. I cannot believe I forgot about that.