shader文件:
Shader "Custom/Logo" {
Properties { _MainTex ("Texture", 2D) = "white" { } _Spec ("Texture", 2D) = "white" { }//透明渐变的图 } SubShader { pass { Tags {"IgnoreProjector"="True" "RenderType"="Transparent"} ZWrite off Blend SrcAlpha OneMinusSrcAlpha CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" sampler2D _MainTex; sampler2D _Spec; float _show; float4 _MainTex_ST; float4 _Spec_ST; struct v2f { float4 pos : SV_POSITION; float2 uv : TEXCOORD0; float2 uv2 : TEXCOORD1; } ; v2f vert (appdata_base v) { v2f o; o.pos = mul(UNITY_MATRIX_MVP,v.vertex); o.uv = TRANSFORM_TEX(v.texcoord,_MainTex); o.uv2 = TRANSFORM_TEX(v.texcoord,_Spec); return o; } float4 frag (v2f i) : COLOR { float4 outp; float4 texCol = tex2D(_MainTex,i.uv); float4 texSpec = tex2D(_Spec,i.uv2); outp = texCol; if(texCol.w > 0.5) { outp += float4(texSpec.x,texSpec.y,texSpec.z,1)*texSpec.w ; } if(_show >0) return outp; else return texCol; } ENDCG } } Fallback "Unlit/Transparent"}shaderController:
public class ShaderControll : MonoBehaviour {
bool flag; // Use this for initialization void Start () { flag=false; InvokeRepeating("Fire",1,2); } // Update is called once per frame void Update () { if(flag) { renderer.material.SetFloat("_show",1); renderer.material.SetTextureOffset("_Spec",new Vector2(1 * Time.time,0)); } else { renderer.material.SetFloat("_show",-1); } } void Fire() { renderer.material.SetTextureOffset("_Spec",new Vector2(0,0)); flag=true; Invoke("SetFlag",0.5f); } void SetFlag() { flag=false; }}