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
}
}
使用纹理制作特效 - 让精灵表单动起来
最新推荐文章于 2025-09-11 07:19:44 发布
本文介绍了一种使用 Unity Shader 实现精灵动画的方法。通过调整纹理宽度、单元格数量和速度属性,可以在运行时自动播放动画。此 Shader 适用于 Opaque 渲染类型,并利用 CGPROGRAM 和 Surface Shader 来实现动画效果。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
ACE-Step
音乐合成
ACE-Step
ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言
1139

被折叠的 条评论
为什么被折叠?



