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

6 Answers

6

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

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, assuming the UV map was set up properly.)

–

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 ("_MainTex", Vector2(0,-offset));

–

Thanks worked perfect!

–

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

–

OK 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

–

Good thank you very much im going to try this out

–

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…

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.

–

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));
    }
}