is there any reason why something like this (from the wiki) does not animate a secondary texture when for instance i change "_MainTex" to "_AlphaTex"? i've tried a few different scenarios nothing seems to animate except the main texture. Code (csharp): var uvAnimationTileX = 4; var uvAnimationTileY = 4; var framesPerSecond = 10.0; function Update () { // Calculate index var index : int = Time.time * framesPerSecond; // repeat when exhausting all frames // index = index % (uvAnimationTileX * uvAnimationTileY); // Size of every tile var size = Vector2 (1.0 / uvAnimationTileX, 1.0 / uvAnimationTileY); // split into horizontal and vertical index var uIndex = index % uvAnimationTileX; var vIndex = index / uvAnimationTileX; // build offset // v coordinate is the bottom of the image in opengl so we need to invert. var offset = Vector2 (uIndex * size.x, 1.0 - size.y - vIndex * size.y); renderer.material.SetTextureOffset ("_AlphaTex", offset); renderer.material.SetTextureScale ("_AlphaTex", size); }
yep - i would open whatever shader i was working with copy the text directly from that. hold on though - i just tried to throw together an example with the terrain 2-layer this script - it seemed to work fine. Code (csharp): var offset = 0.0; var offsetSpeed = 0.5; function Update() { offset = Time.time * offsetSpeed; renderer.material.SetTextureOffset ("_Mask", Vector2(-offset, 0)); } (i was fooling around with stuff for explosivo just remembered i wanted to ask this - but now i have to remember what shader i was using at the time ; )
i found one example - the XRay shader. trying to animate "_RampTex" doesn't seem to do anything. there was another that i couldn't get going though but i can't seem to find it atm - i was trying all sorts of wacky things a few weeks ago now i've forgotten ; ) i'm working now but i will look more later if you want make up a package for you to check out.
Well, it does not work in XRay shader because it uses a custom vertex program where it does not apply texture scale&offset (this might be for simplicity or for performance reasons, or both). All built-in Unity shaders do apply texture scale&offset, but custom written ones... well, you get what is implemented there, and a vertex shader might apply scale&offset, or it might not.