Skip to content

Instantly share code, notes, and snippets.

@daichi-takezawa
Created April 28, 2020 11:54
Show Gist options
  • Save daichi-takezawa/50e78a552496d06fcbda70877c03317d to your computer and use it in GitHub Desktop.
Save daichi-takezawa/50e78a552496d06fcbda70877c03317d to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MeshCreate : MonoBehaviour
{
private MeshFilter meshFilter;
public Material material;
private MeshRenderer meshRenderer;
void Start()
{
Vector3[] vertices = {
new Vector3(-1f, -1f, 0),
new Vector3(-1f, 1f, 0),
new Vector3( 1f, 1f, 0),
new Vector3( 1f, -1f, 0)
};
int[] triangles = { 0, 1, 2, 0, 2, 3 };
Mesh mesh = new Mesh();
mesh.vertices = vertices;
mesh.triangles = triangles;
mesh.RecalculateNormals();
meshFilter = GetComponent<MeshFilter>();
meshFilter.mesh = mesh;
meshRenderer = GetComponent<MeshRenderer>();
meshRenderer.sharedMaterial = material;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment