- Home /
Cannot create mesh from code,Cannot use Script to Generate 2d mesh
Despite following tutorials and rewriting code again and again I just cannot get this 2d mesh to show up in the game: using System.Collections; using System.Collections.Generic; using UnityEngine;
[RequireComponent(typeof(MeshFilter))]
public class SandGenerator : MonoBehaviour { Mesh mesh; public Vector3[] vertices; public int[] triangles;
private void Start() { mesh = new Mesh(); GetComponent().mesh = mesh; CreateShape(); UpdateMesh(); }
void CreateShape()
{
vertices = new Vector3[3];
vertices[0] = new Vector3 (0,0,0);
vertices[1] = new Vector3 (1,0,1);
vertices[2] = new Vector3 (0,0,1);
triangles = new int[3];
triangles[0] = 0;
triangles[1] =2;
triangles[2] =1;
}
void UpdateMesh ()
{
mesh.Clear();
mesh.vertices = vertices;
mesh.triangles = triangles;
}
},Despite following tutorials and re-writing the code again and again I just cannot get a simple mesh to appear. Any help would be great, what am I doing wrong? using System.Collections; using System.Collections.Generic; using UnityEngine;
[RequireComponent(typeof(MeshFilter))]
public class SandGenerator : MonoBehaviour { Mesh mesh; public Vector3[] vertices; public int[] triangles;
private void Start() { mesh = new Mesh(); GetComponent().mesh = mesh; CreateShape(); UpdateMesh(); }
void CreateShape()
{
vertices = new Vector3[3];
vertices[0] = new Vector3 (0,0,0);
vertices[1] = new Vector3 (1,0,1);
vertices[2] = new Vector3 (0,0,1);
triangles = new int[3];
triangles[0] = 0;
triangles[1] =2;
triangles[2] =1;
}
void UpdateMesh ()
{
mesh.Clear();
mesh.vertices = vertices;
mesh.triangles = triangles;
}
}
Your answer
Follow this Question
Related Questions
2D Sprite constantly flipping 0 Answers
Super Mario Bros 2D very lagging 1 Answer
How can I disable a Method. 1 Answer
Don't Flip Child, Only Parent. 0 Answers
(C#) SetActive isn't working on my UI 2 Answers