Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using UnityEngine;
using System.Collections;
[RequireComponent (typeof(MeshRenderer))]
[RequireComponent (typeof(MeshFilter))]
public class DynamicCreateMesh : MonoBehaviour
{
[SerializeField]
private Material _mat;
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
};
// 修正箇所 : 各頂点に対してUV座標を設定しています
mesh.uv = new Vector2[] {
new Vector2 (0.5f, 1f),
new Vector2 (1f, 0),
new Vector2 (0, 0),
};
mesh.RecalculateNormals ();
var filter = GetComponent<MeshFilter> ();
filter.sharedMesh = mesh;
var renderer = GetComponent<MeshRenderer> ();
renderer.material = _mat;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment