Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GraphicsMeshSample : MonoBehaviour {
- static public Material material;
- static public Mesh meshCache = null;
- void Update () {
- Vector3 position = transform.position;
- Quaternion rotation = transform.rotation;
- Vector3 scale = transform.lossyScale;
- Matrix4x4 matrix = Matrix4x4.TRS(position, rotation, scale);
- Graphics.DrawMesh(GetMesh(), matrix, material, 0);
- }
- static public Mesh GetMesh() {
- if (meshCache == null) {
- meshCache = new Mesh();
- int size = 1;
- meshCache.vertices = new Vector3[] {
- new Vector3(-size, -size, 0.01f),
- new Vector3(-size, size, 0.01f),
- new Vector3(size, size, 0.01f),
- new Vector3(size, -size, 0.01f)
- };
- meshCache.uv = new Vector2[] {
- new Vector2 (0, 0),
- new Vector2 (0, 1),
- new Vector2(1, 1),
- new Vector2 (1, 0)
- };
- meshCache.triangles = new int[] { 0, 1, 2, 0, 2, 3};
- meshCache.RecalculateNormals();
- }
- return(meshCache);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement