- Select the original Texture (not the GameObject).
- Change
Texture Type
toSprite (2D and UI)
. - Change
Wrap Mode
toRepeat
. - Click
Apply
. - Create a
Quad
object:GameObject -> 3D Object ->Quad
. - Scale the
Quad
to the size you want. - Create a light:
GameObject->Light->Directional Light
. - Adjust the light intensity to whatever you like.
- Drag your Texture/Sprite to the
Quad
in the Scene View.
Now, create your script:
public class OffsetScrolling : MonoBehaviour {
public float scrollSpeed;
private Renderer renderer;
private Vector2 savedOffset;
void Start () {
renderer = GetComponent<Renderer> ();
}
void Update () {
float x = Mathf.Repeat (Time.time * scrollSpeed, 1);
Vector2 offset = new Vector2 (x, 0);
renderer.sharedMaterial.SetTextureOffset("_MainTex", offset);
}
}
Note: For 2D, you can also use a Plane
and the code above should work fine.
References:
Nice, thank you! Exactly what I needed. Quick note: you can change the direction of the moving texture by giving it a negative scrollSpeed.