描述
不用脚本,只用shader来实现序列动画
代码如下
Shader "Effects/XuLie"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Color ("color",color) = (1,1,1,1)
_AmountH ("AmountH",float) = 4 //水平方向
_AmountV ("AmountV",float) = 4 //垂直方向
_Speed ("speed",Range(1,100)) = 30
}
SubShader
{
Tags { "Queue"="Transparent" "RenderType"="Transparent" }
LOD 100
ZWrite Off
Blend SrcAlpha One
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float2 uv2: TEXCOORD1;
};
sampler2D _MainTex;
float4 _MainTex_ST;;
float4 _Color;
float _AmountH;
float _AmountV;
float _Speed;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float time = floor(_Time.y * _Speed);//floor():取整,保证uv按照一定的间隔移动
float row = floor(time / _AmountH);
float column = time - row * _AmountH;
half2 uv = i.uv + half2 (column ,-row);
uv.x /= _AmountH ;
uv.y /= _AmountV ;
fixed4 col = tex2D(_MainTex, uv)*_Color;
return col;
}
ENDCG
}
}
}
亲,如果您觉得本文不错,愿意给我一些动力的话,请用手机扫描二维码即可向我打赏