Created
October 7, 2015 15:30
-
-
Save davepape/7209e9807b0bc0eb8baa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma strict | |
public var rows = 30; | |
public var cols = 30; | |
private var myVertices = Array(); | |
private var myUVs = Array(); | |
private var myTriangles = Array(); | |
function Start () | |
{ | |
for (var i=0; i < rows; i++) | |
{ | |
for (var j=0; j < cols; j++) | |
{ | |
myVertices.push(Vector3(j-cols/2.0,i-rows/2.0,0)); | |
myUVs.push(Vector2(j/(cols-1.0),i/(rows-1.0))); | |
} | |
} | |
for (i=0; i < rows-1; i++) | |
{ | |
for (j=0; j < cols-1; j++) | |
{ | |
myTriangles.push(i*cols+j); | |
myTriangles.push((i+1)*cols+j); | |
myTriangles.push(i*cols+j+1); | |
myTriangles.push((i+1)*cols+j); | |
myTriangles.push((i+1)*cols+j+1); | |
myTriangles.push(i*cols+j+1); | |
} | |
} | |
var m = GetComponent.<MeshFilter>().mesh; | |
m.vertices = myVertices; | |
m.uv = myUVs; | |
m.triangles = myTriangles; | |
m.RecalculateNormals(); | |
} | |
function Update () | |
{ | |
var index=0; | |
for (var i=0; i < rows; i++) | |
{ | |
for (var j=0; j < cols; j++) | |
{ | |
myUVs[index] = Vector2(j/(cols-1.0)+Mathf.Sin(Time.time+i)/50.0,i/(rows-1.0)+Mathf.Cos(Time.time+j)/50.0); | |
index++; | |
} | |
} | |
var m = GetComponent.<MeshFilter>().mesh; | |
m.uv = myUVs; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment