using UnityEngine;
using System.Collections;
public class WaterSin : MonoBehaviour {
GameObject gameobject1;
MeshFilter meshFlider;
MeshRenderer meshRender;
public Material material;
private float totalHeight;
// Use this for initialization
void Start()
{
//Create Mesh
gameobject1 = new GameObject("Mesh");
meshFlider = gameobject1.AddComponent<MeshFilter>();
meshRender = gameobject1.AddComponent<MeshRenderer>();
meshRender.material = material;
meshFlider.mesh = new Mesh();
Vector3[] veritices = new Vector3[20];
Vector3[] normal = new Vector3[20];
Vector2[] uv = new Vector2[20];
int[] triangles = new int[18 * 3];
for (int i = 0; i < 10; i++)
{
veritices[i] = new Vector3(i - 5, 0, 0);
veritices[i + 10] = new Vector3(i - 5, 1, 0);
uv[i] = new Vector2(0.1f * i, 0);
uv[i+10] = new Vector2(0.1f * i, 1);
normal[i] = new Vector3(0, 1, 0);
normal[i + 10] = new Vector3(0, 1, 0);
}
for (int i = 0; i < 9; i++)
{
triangles[i * 3] = i;
triangles[i * 3 + 1] = i + 10;
triangles[i * 3 + 2] = i + 1;
triangles[(i + 9) * 3] = i + 10;
triangles[(i + 9) * 3 + 1] = i + 11;
triangles[(i + 9) * 3 + 2] = i + 1;
}
meshFlider.mesh.vertices = veritices;
meshFlider.mesh.triangles = triangles;
meshFlider.mesh.uv = uv;
meshFlider.mesh.normals = normal;
meshFlider.mesh.RecalculateBounds();
}
// Update is called once per frame
void Update () {
MeshWave();
}
void MeshWave()
{
Vector3[] vertices = meshFlider.mesh.vertices;
Vector2[] uv = meshFlider.mesh.uv;
for (int i = 10; i < 20; i++)
{
float meshHeight = totalHeight+0.3f*Mathf.Sin(0.5f*vertices[i].x + Time.time * 4.0f);
vertices[i] = new Vector3(vertices[i].x, meshHeight, 0);
uv[i] = new Vector2(uv[i].x, meshHeight / 11);
}
meshFlider.mesh.vertices = vertices;
meshFlider.mesh.uv = uv;
}
void OnGUI()
{
totalHeight = GUI.HorizontalScrollbar(new Rect(25, 25, 100, 30), totalHeight, 1.0F, 0.0F, 10.0F);
}
}
MESH水面波动效果和通过UV制作遮罩
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 干货要点: 1、叙述、描写和说明是三种记“实”的能力。 2、议论和抒情是两种写“虚”的能力。 3、根据表达的中心,...