- Home /
Offset detail texture in c#
Trying to make an "animated" gui health bar. I have a material whose shader I have set up as Diffuse Detail. (I don't know much about materials. It was the only shader I could find that suited my needs.) In code, I offset the material to create an animated effect (I've done this on non GUI materials in my game and it worked just fine)
float x = Time.time;
float y = Time.time / 2;
mightyFire.mainTextureOffset = new Vector2 (x, y);
the only problem is it's changing the main texture, which doesn't do anything, and I need to change the offset of the DETAIL texture. I can't find a way to do this in the Unity Manual.
Answer by robertbu · Oct 22, 2014 at 07:48 PM
Use this function:
http://docs.unity3d.com/ScriptReference/Material.SetTextureOffset.html
'_Detail' will be your property name:
renderer.material.SetTextureOffset("_Detail", new Vector2(x, y));
thanks! this worked perfectly. i can't upvote you because i'm not cool enough :(
Upvoting comes with 15 karma points, so get a thumbs up for a couple of comments or get one accepted answer, and you can upvote.
Your answer
Follow this Question
Related Questions
Tile and offset a Texture2D? 2 Answers
GUI Style Issue-- Texture not changing 2 Answers
Scroll Ball Texture Smoothly 0 Answers
Same BackGroung For All Screen Resolution 1 Answer
Assigning script-generated textures 0 Answers