NullReferenceException: Object reference not set to an instance of an object
Procedural_Mesh.CreateMesh () (at Assets/Procedural_Mesh.cs:31)
Procedural_Mesh.Start () (at Assets/Procedural_Mesh.cs:19)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(MeshFilter))]
public class Procedural_Mesh : MonoBehaviour {
Mesh mesh;
Vector3[] vertices;
int[] triangles;
void awake()
{
mesh = GetComponent<MeshFilter> ().mesh;
}
// Use this for initialization
void Start () {
MakeMeshData();
CreateMesh();
}
void MakeMeshData()
{
vertices = new Vector3[] { new Vector3(0, 0, 0), new Vector3(0, 0, 1), new Vector3(1, 0, 0) };
triangles = new int[] { 0, 1, 2 };
}
void CreateMesh()
{
this. mesh.Clear();
this. mesh.vertices = vertices;
this.mesh.triangles = triangles;
}
}