Created
August 8, 2018 18:05
-
-
Save nothke/b0fd447cd3d3e60b13c14e6d8bba9205 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
public class MeshSetAtStart : MonoBehaviour | |
{ | |
MeshFilter meshFilter; | |
// Reference to the mesh | |
Mesh mesh; | |
void Start() | |
{ | |
meshFilter = gameObject.AddComponent<MeshFilter>(); | |
gameObject.AddComponent<MeshRenderer>(); | |
// Create the mesh once, at start | |
mesh = new Mesh(); | |
meshFilter.mesh = mesh; | |
} | |
void Update() | |
{ | |
Vector3[] vertices = new Vector3[4]; | |
// Create vertices of the quad, and add a random position to each vertex | |
vertices[0] = new Vector3(-1, -1, 0) + Random.insideUnitSphere * 0.1f; | |
vertices[1] = new Vector3(-1, 1, 0) + Random.insideUnitSphere * 0.1f; | |
vertices[2] = new Vector3(1, -1, 0) + Random.insideUnitSphere * 0.1f; | |
vertices[3] = new Vector3(1, 1, 0) + Random.insideUnitSphere * 0.1f; | |
// Triangles | |
int[] triangles = new int[6] { | |
0, 1, 2, | |
1, 3, 2 }; | |
mesh.vertices = vertices; | |
mesh.triangles = triangles; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment