- Home /
Material.mainTextureOffset,...how do I use this?
I'm trying to making my texture animate by scrolling it rapidly from side to side... I've found several answers here, all pointing to "Material.mainTextureOffset", which then brings up a page that shows multiple lines of scripting...
I'm VERY new to Unity, and I'm not sure how I'm supposed to use this code... Do I cut and paste it into a certain shader? If it's the Diffuse shader, Unity doesn't seem to let me access the script...
Please, I'd be very appreciative if someone would explain to me exactly how I use Material.mainTextureOffset to make my textures scroll...
Answer by Berenger · May 04, 2012 at 10:08 PM
Inside unity's code, when the object is drawn, the material will give that offset to the shader. You don't need to change the shader what so ever in that case.
What you need to do though, is a a reference to that material, probably in a class inheriting from MonoBehaviour (if your using javascript, it means a regular script). Then affect a new value to the property material.mainTextureOffset. Now, you want this to be animated, so you'll need to give a new value to mainTextureOffset each times you want the result to change.
If you need more details, I'll can explain further.
Thanks Bérenger, I'd certainly love more details... Without help, I'm worried that this may be beyond me at the moment...
I'm an environment artists who has gotten used to using Gamebryo (in my last project), which simply sees that you've animated the UVs of an object when you import it... And in the game, it simply works...
I'm not used to having to script basic UV settings to make them work, so this may be a bit tough for me...
I'd really appreciate if you can walk me through the steps...
O$$anonymous$$,..so I've started by opening the material in the Inspector in Unity, and I have applied an Offset of 1 in the "Y" direction (which I'm assu$$anonymous$$g means "up")...
Now that I've done that, where do I access the interface in Unity to make a reference to that material (in other words, how do I get to where I implant and affect the $$anonymous$$aterial.mainTextureOffset code)?
I added a scene example to the wiki, but read the following first.
Each gameObject in unity contains a collection of components. You have the built-in like Transform, $$anonymous$$eshRenderer, BoxCollider, or the scripts for more control.
When you attach a script to a gameobject, the code inside will be executed on this instance at the proper time. You can access the other components of the gameobject with some properties provided by Unity, among other ways.
In that case, you need access to the renderer, which contains the material. Then, you can modify mainTextureOffset. It takes a Vector2.
I hope it helps you.
Your answer
Follow this Question
Related Questions
texture offset question 2 Answers
UV Animation export from Maya? 1 Answer
Eyes animation texture problem 0 Answers
Can u3 support 3dmax physical model directly importting? 0 Answers
Adding a UV offset to tex2dproj. 1 Answer