- 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 GenericToast · May 20, 2020 at 08:24 AM
In the import settings of your background texture, change the Wrap Mode to "Repeat"
Your answer
Follow this Question
Related Questions
Assigning script-generated textures 0 Answers
Why the gui texture is not in the middle of the screen and how can i change the texture size ? 1 Answer
Renderer on object disabled after level reload 1 Answer
How to fill texture that would be avaliable to ither shaders? 1 Answer
Blend 2 Textures Unity C# 0 Answers