- Home /
Scroll Texture with Wrap
Hi - I really appreciate any help on this.
I want to scroll a texture across a plane but have the texture wrap itself as it goes off one end it comes back along the other. Think of clouds that scroll across a plane from right to left, as part of the first cloud goes off the left side of the plane it immediately starts to appear on the right side of the plane. My code is below...
private int materialIndex = 0;
private Vector2 uvAnimationRate = new Vector2( 0.01f, 0.0f );
private string textureName = "_MainTex";
Vector2 uvOffset = Vector2.zero;
void LateUpdate()
{
uvOffset += ( uvAnimationRate * Time.deltaTime );
if( renderer.enabled )
{
// This is choppy and doesn't 'wrap' correctly
renderer.materials[ materialIndex ].SetTextureOffset( textureName, WrapVector(renderer.materials[ materialIndex ].GetTextureOffset(textureName) + new Vector2(0.1f, 0.0f) * 0.1f));
// This just moves the texture from left to right no wrapping at all
renderer.materials[ materialIndex ].SetTextureOffset( textureName, uvOffset );
}
}
Vector2 WrapVector(Vector2 input)
{
return new Vector2(input.x - (int)input.x, input.y - (int)input.y);
}
On your texture import settings, make sure the Wrap $$anonymous$$ode is set to 'Repeat' and not 'Clamp'.
Answer by iPedro · Aug 16, 2013 at 10:41 PM
Thank you - this worked. I had my Texture Type as GUI so I didn't see this option before. After changing the texture type to texture the option to 'Repeat' was available
Your answer
Follow this Question
Related Questions
Material/Texture on the Inside of a Sphere 5 Answers
How can I swap an object's texture when I click? 2 Answers
Transparent shader and scrolling 0 Answers
CRT/LCD screen shader (for materials) 4 Answers