Let the animation play this texture from 1-9 cycles
Source:
Shader "Sbin/fragmentanim" {Properties{_maintex ("Texture", 2D) = "White" {}}subshader{pass{cgprogram#pragma vertex Vert#pragma fragment Frag#include "Unitycg.cginc" sampler2d _maintex;float4 _maintex_st;//Texture scaling offset vector (unity defaults to this variable assignment, Variable name rule: Texture name _st) struct V2F{FLOAT4 pos:position;float2 uv:texcoord0;}; v2f Vert (Appdata_full v) {v2f O;o.pos = Mul (UNITY_MATRIX_MVP, V.vertex); o.uv = V.texcoord.xy * _maintex_st.xy + _MainTex_S T.zw;return o;} Fixed4 Frag (v2f v): color{fixed4 col = tex2d (_maintex, V.UV);//First parameter: texture, second parameter UV vector return col;} ENDCG}}}
using Unityengine;using System.collections;public class fragmentanim:monobehaviour{public int rowCount; Line number public int columcount; Number of columns public int fps; Playback speed private int currentindex;//current playback index value IEnumerator Start () {Material mat = Getcomponent<renderer> ;(). Material; float itemwidth = 1.0f/rowcount; Each frame width float itemheight = 1.0f/columcount; Height per frame while (true) {float offset_x = currentindex% Columcount * itemwidth; float offset_y = Currentindex/rowcount * itemheight; Mat. Settexturescale ("_maintex", New Vector2 (Itemwidth, itemheight)); Mat. Settextureoffset ("_maintex", New Vector2 (offset_x, offset_y)); Yield return new waitforseconds (1/FPS); Currentindex = (++currentindex)% (RowCount * columcount); } }}
Getting Started with CG 23:fragment SHADER–UV animations (sequence frames)