Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using UnityEngine;
[RequireComponent (typeof(MeshRenderer))]
[RequireComponent (typeof(MeshFilter))]
public class DynamicCreateMesh : MonoBehaviour
{
[SerializeField] Material _colorMaterial;
private void Start ()
{
var mesh = new Mesh ();
mesh.vertices = new Vector3[] {
new Vector3 (0, 1f),
new Vector3 (1f, -1f),
new Vector3 (-1f, -1f),
};
mesh.triangles = new int[] {
0, 1, 2
};
mesh.RecalculateNormals ();
var filter = GetComponent<MeshFilter> ();
filter.sharedMesh = mesh;
var meshRenderer = GetComponent<MeshRenderer>();
// MeshRendererにMaterialをセット
meshRenderer.material = _colorMaterial;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment