- Home /
Creating a mesh for an overview map
I am generating a 2d procedurally generated map, and I would like to create a map to display an overview of said map. As i know it will be slow to have a game object on the overview map for every single tile in the world, I have decided to use a mesh. Having never used meshes before I am running into some trouble.
I have a meshFilter like so:
private MeshFilter meshFilt;
meshFilt = GetComponent<MeshFilter>();
and I am then trying to set the vertices of the mesh to the locations of the tiles:
mesh = meshFilt.mesh;
Vector3[] keys = revealedTiles.Keys.ToArray<Vector3>();
mesh.vertices = keys;
Color[] colors = new Color[mesh.vertices.Length];
Random r = new Random();
for (int i = 0; i < keys.Length; i++)
{
colors[i] = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f));
}
mesh.colors = colors;
Where keys is an array of Vector 3's, which are part of a dictionary. So basically what I am doing is setting the vertices of the mesh to an array of vector3's that represent the map coordinates of every tile (1,1 1,2 2,5 .etc).
Currently I am just setting the colors to a random color, just as a proof of concept.
However, the issue is that this does not seem to display anything. In the unity scene view I am getting an outline of a box that appears to be the right size, but it has nothing within it. In the game view nothing appears. I have checked that this code is running, and all of the vertices are being set properly. Any and all help is appreciated, and if anyone has a better idea on how to do this, I am more than willing to listen.
Thank you.
Edit: Here is a view of the scene view:
You are assigning vertex positons, but you don't built any triangles from them so there is in fact nothing to display: No real mesh exists as there are no polygons in it, justa bunch of vertices with no connections between them. Also note that if you assign colors to the vertices, you have to use a shadeder that supports vertex colors, otherwise the colors won't show.
Check the Unity API for the $$anonymous$$esh class for an example of how to built a mesh by script.
I agree, look it up here:
http://docs.unity3d.com/ScriptReference/$$anonymous$$esh.html
Your answer
Follow this Question
Related Questions
Why vertex positions appear (0.0, 0.0, 0.0) ? 1 Answer
Mesh.vertices are all 0? 1 Answer
Mesh Vertices Welding 0 Answers