步骤
简单的瀑布效果,简单地分为以下四个步骤
网格
纹理及纹理的设置
shader
Shader "Mobile/流水(Test)" {
Properties {
_TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
_EmissiveStrength ("Emissive strength", Range (0,1)) = 0.5
_Translulency ("Translulency", Range (0,1)) = 1.0
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 200
Cull Off Lighting Off ZWrite Off
Blend SrcAlpha One
AlphaTest Greater .01
ColorMask RGB
CGPROGRAM
#pragma surface surf Lambert alpha
fixed4 _TintColor;
half _EmissiveStrength;
half _Translulency;
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D(_MainTex, IN.uv_MainTex);
//o.Albedo = 2*c*_TintColor;
o.Emission = 2*c*_TintColor*_EmissiveStrength;
o.Alpha = 2*(c.a /* (c.r+c.g+c.b)/3*/)*_Translulency;
}
ENDCG
}
Fallback "Transparent/Diffuse"
}
- 脚本(修改瀑布对象的Material的Texture的Offset属性,即纹理的偏移量)
using UnityEngine;
using System.Collections;
public class uvAnimation : MonoBehaviour
{
public int materialIndex;
public string textureName = "_MainTex";
public Vector2 uvAnimationRate = new Vector2(1f, 0f);
private Vector2 uvOffset = Vector2.zero;
private void LateUpdate()
{
uvOffset += (Vector2) (uvAnimationRate * Time.deltaTime);
if (GetComponent<Renderer>().enabled)
{
if(GetComponent<Renderer>().materials.Length > materialIndex){
GetComponent<Renderer>().materials[materialIndex].SetTextureOffset(textureName, uvOffset);
}
}
}
}