Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by 3Nex · Aug 09, 2014 at 01:52 PM · textureoffsettexturing

How do I programmatically change the offset of a texture?

alt text

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)?

untitled.jpg (20.2 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image 3Nex · Aug 09, 2014 at 05:05 PM 0
Share

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.

avatar image
1

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

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));

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Best way of scrolling a texture without lagging? 0 Answers

Offset detail texture in c# 1 Answer

How to move a specific texture from a shader? 0 Answers

SetTextureOffset not visible 1 Answer

Having Trouble with Texture Tiling and offset values. Very specific case. 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges