My Script call no errors when executed, but I see no objects on the screen. What’s wrong ?
var plane : GameObject;
var size = Vector2(2,2);
var position = Vector3(0,0,0);
var material : Material = new Material (Shader.Find(" Diffuse"));
private var myFilter : MeshFilter;// = plane.AddComponent(MeshFilter);
private var myRenderer : MeshRenderer;// = plane.AddComponent(MeshRenderer);
private var myMesh : Mesh;// = new Mesh ();
private var count : int;// = (size.x+1)*(size.y+1);
function Start () {
if (!plane) plane = new GameObject();
myFilter = plane.AddComponent(MeshFilter);
myRenderer = plane.AddComponent(MeshRenderer);
myMesh = new Mesh ();
count = (size.x+1)*(size.y+1);
myMesh.vertices = new Vector3[count];
myMesh.triangles = new int[(size.x*size.y)*6];
myMesh.uv = new Vector2[count];
var dim = Vector3(1/size.x,0,1/size.y);
var ori = Vector3(-0.5,0,-0.5);
var vind : int = 0;
for (var i=0; i<=size.y; ++i) {
for (var j=0; j<=size.x; ++j) {
myMesh.vertices[vind] = Vector3(ori.x+dim.x*j,0,ori.z+dim.z*i); //vertex position
myMesh.uv[vind] = Vector2(j*dim.x,1-(i*dim.z)); //vertex texture coord
vind++;
}
}
tris();
myMesh.RecalculateNormals();
myFilter.mesh = myMesh;
myFilter.mesh.name = plane.name + "_mesh";
myRenderer.material = material;
}
function tris()
{
var fcount : int = (size.x*size.y*2);
var find = 0;
for (var i=0; i<size.y; ++i) {
for (var j=0; j<size.x; ++j) {
var a : int = j + i*(Mathf.Floor(size.x)+1);
var b : int = j + (i+1)*(Mathf.Floor(size.x)+1);
myMesh.triangles[find++] = a;
myMesh.triangles[find++] = b+1;
myMesh.triangles[find++] = a+1;
myMesh.triangles[find++] = a;
myMesh.triangles[find++] = b;
myMesh.triangles[find++] = b+1;
}
}
}