- Home /
Animated material?
How can i make a material that is animated? Such as making animated lava or some other type of material that is constantly changing? Thanks for any help :)
Answer by Cherno · Apr 19, 2015 at 06:06 PM
Here are a few scripts that use a sprite sheet.
Thanks for your answer but i was hoping there would be a method without using sprite sheets as i don't know how to make them really... maybe having 1 texture and "moving" it or something?
What do you mean, you don't know how to make them? It's just a big image with several smaller images inside :) Even $$anonymous$$S Paint can do this! :)
Other than that, here's a simle scrolling uv script like Owen was talking about.
var uvOffset : Vector2 = Vector2.zero;
var materialIndex : int = 0;
var uvAnimationRate : Vector2 = new Vector2( 0.0f, 1.0f );
var textureName : String = "_$$anonymous$$ainTex";
function Update ()
{
uvOffset += ( uvAnimationRate * Time.deltaTime );
if( renderer.enabled )
{
renderer.materials[ materialIndex ].SetTextureOffset( textureName, uvOffset );
}
}
Answer by Owen-Reynolds · Apr 19, 2015 at 06:29 PM
You can change the Material's Offsets, in code, to scroll the material. Can also change the scaling, usually back and forth. A tiny change goes a long way, like between 0.9 and 1.1.
I think the built-in blend shader uses the same offsets for each texture. Otherwise you could move them at different speeds.
For a good animated texture, use a shader that keys off time (or other things you might set.) If you can find one, learning to write them is a huge pain (use Unity surface or frag/vert shaders. Not the shaderLab ones, since they can be configured. but not really programmed.)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Changing material on an object multiple times 0 Answers
Gl.Lines appearing over objects 0 Answers
How to create a complex material in an Editor-Script? C# 0 Answers