Shader "SpriteAnimate"
{
Properties
{
_MainTex("MainTex", 2D) = "white" {}
_TexWidth("TexWidth", float) = 0.0
_CellAmount("CeilAmount", float) = 0.0
_Speed("Speed", range(0.01, 32)) = 10
}
SubShader
{
Tags
{
"RenderType" = "Opaque"
}
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
float _TexWidth;
float _CellAmount;
float _Speed;
struct Input
{
float2 uv_MainTex;
};
void surf(Input IN, inout SurfaceOutput o)
{
float2 spriteUV = IN.uv_MainTex;
float cellUVPercentage = 1.0 / _CellAmount;
float timeValue = fmod(_Speed * _Time.y, _CellAmount);
timeValue = ceil(timeValue);
float xValue = spriteUV.x;
xValue += timeValue;
xValue *= cellUVPercentage;
spriteUV = float2(xValue, spriteUV.y);
half4 c = tex2D(_MainTex, spriteUV);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
}