- Home /
Scroll using material.mainTextureOffset makes the texture very distorted
Hey, Everyone, I am using a simple line of code to scroll the texture in material to get a moving background feel.
public float scrollSpeed;
private MeshRenderer backgroundImage_Menu;
private float offset;
private void Start()
{
backgroundImage_Menu = GetComponent<MeshRenderer>();
}
private void Update()
{
offset += (Time.deltaTime * scrollSpeed) / 10f;
// backgroundImage_Menu.material.SetTextureOffset("_MainTex", new Vector2(offset, 0));
backgroundImage_Menu.material.mainTextureOffset = new Vector2(offset, 0);
}
Here is the pretty basic code to scroll the texture. But using it makes the texture scroll but distorts it from the side it started moving(It's hard to understand what I said, so Attaching an Image)
This is what the texture looks like
And, this is what happens after scrolling for a while
Do you see what's happening here? I have no idea why it's happening. This used to work before. I have used it before and it worked last time. But, I am not really sure why it's happening this time. I also checked with the official unity document here and they did pretty much the same thing. Can this be a bug? Please any suggestions would be appreciated.
Thank you :),
stay safe during this pandemic,
Bhavin Lathia.
Answer by Q-Ted · May 20, 2020 at 06:07 AM
This looks like what happens when the Wrap Mode of the texture is set to "Clamped". Check your texture's import settings and make sure it is set to "Repeat" or "Mirror".
You can find additional information about the Texture Importer here: https://docs.unity3d.com/Manual/class-TextureImporter.html
Thanks a lot, Sir. It worked. I had no idea about this setting. I set it to "$$anonymous$$irror", setting it to Repeat was making the repeated texture (I guess it's called that), darker.
Your answer
Follow this Question
Related Questions
Assigning script-generated textures 0 Answers
Object turns pink when changing material at real time: 1 Answer
Texture2D to Texture3D 2 Answers
Setting texture for a transparent material in c# 0 Answers
WebGL VideoTexture not working 0 Answers