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

This is an example using SetTextureOffset :

[Unity - Scripting API: Material.SetTextureOffset][1]


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 __+= Vector2( scrollSpeed * Time.deltaTime, 0 );__

}

mesh.uv = uvSwap;
}
[1]: Unity - Scripting API: Material.SetTextureOffset

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

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.

OK and what is the best example between those 2 answers ?

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… :frowning:

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…

Its in Unity Docs See Here Material.SetTextureOffset

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public float scrollSpeed = 0.5F;
    public Renderer rend;
    void Start() {
        rend = GetComponent<Renderer>();
    }
    void Update() {
        float offset = Time.time * scrollSpeed;
        rend.material.SetTextureOffset("_MainTex", new Vector2(offset, 0));
    }
}