- Home /
How do I programmatically change the offset of a texture?
I have a surface for a television screen, which has the texture of static applied. So, to make the static actually happen, I want to programmatically change the offset of the texture every couple of frames.
But, I don't know what the property or method is called, or how I can access the texture and its offset. How do I write the code to accomplish changing the offset (from a parent object)?
Answer by robertbu · Aug 09, 2014 at 01:57 PM
It is Material.mainTextureOffset. Some sample code in the reference page:
http://docs.unity3d.com/ScriptReference/Material-mainTextureOffset.html
Damn it all, I tried renderer.material.mainTextureOffset.Set (xOffset + .1f, 0);
before, which didn't work and i still don't quite understand why, but with renderer.material.mainTextureOffset = new Vector2(xOffset + .1f, 0);
it does. Thank you for pointing me in the right direction.
Answer by flaviusxvii · Aug 09, 2014 at 01:58 PM
I didn't know.. so I googled... like you should have "unity3d set texture offset"
http://docs.unity3d.com/ScriptReference/Material.SetTextureOffset.html
Answer by codemaker2015 · Apr 15, 2021 at 03:00 PM
Material material = gameObject.GetComponent<Renderer>().material;
offset = 0.001f;
material.SetTextureOffset("_MainTex", new Vector2(0, offset));
Answer by Wothanar · Nov 09, 2020 at 02:15 AM
Its a good point the answer, anyways in my case im looking at how to do this but using mesh.uv , i need to achieve the same result that with the main texture offset but using mesh.uv , anyone know this? coz so far i think this would improve draw calls , other ways , maintextureOffset change i think is not good coz that would still make an extra draw call using atlasing so i believe it dosnt have much sense. thanks
Your answer
Follow this Question
Related Questions
applying textures to meshes from blender? 1 Answer
How can I create a UV move tool? 0 Answers
Tutorials on Basic Level Modeling for Games 1 Answer
Animation Tiling/Offset 0 Answers