Hi guys! Here is my attempt to generate and render an array(list) of simple rectangle meshes. List contains 100 items but Unity renders the only one (i suppose that the problem is because of incorrect using of MeshFilter but im not sure). Also i tried to make simple color changing with OnMouseOver() and here is also fail.
Any suggestions?
Thanks in advance for help!
*on a screenshot the cube is only measure tool.
the code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class test_cuba : MonoBehaviour {
List <Mesh> shtuchki = new List<Mesh>();
void Start () {
for(int n= 0; n < 10; n++){
for (int m=0; m<10; m++){
MeshFilter mfilter = gameObject.GetComponent<MeshFilter>();
Mesh messh = new Mesh();
mfilter.sharedMesh = messh;
Rect rt = new Rect (n,m,1,1);
/*Debug.Log ( rt.x);
Debug.Log (rt.y);*/
messh.vertices = new Vector3 [] {
new Vector3(rt.x,rt.y,0), // ver0
new Vector3(rt.xMax,rt.y,0), // ver1
new Vector3(rt.xMax,rt.yMax,0), // ver2
new Vector3(rt.x,rt.yMax,0), //ver3
};
messh.triangles = new int [] {
0,1,2,
2,3,0,
};
renderer.material.color = Color.white;
messh.RecalculateBounds();
messh.RecalculateNormals();
shtuchki.Add(messh);
Debug.Log("mesh_number: " + shtuchki.Count);
}
}
}
void Update () {
for(int v=0; v<shtuchki.Count; v++){
Graphics.DrawMeshNow(shtuchki[v], Vector3.zero, Quaternion.identity, 0);
}
}
void OnMouseOver() {
renderer.material.color = Color.red;
}
}
ZIP project:
https://www.dropbox.com/s/bj883s3ovnrvpuu/graphs.zip