Created
April 28, 2020 11:54
-
-
Save daichi-takezawa/50e78a552496d06fcbda70877c03317d 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
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