Possibly the stupidest question I’ve asked here yet, but, I seem only able to get the integer part back from what I’m pretty sure is a float calculation!. I’m having flashbacks to FORTRAN and implicitly typed variable names…;^) I’ve tried a bunch of crazy stuff to get a float as you can see in the included code segment but the Debug.Log definitely only shows integer values, (which really messes up mesh alignments!).
Bathys = new GameObject[x_meshes,z_meshes];
float fi = 0;
float fj = 0;
for (int i=0; i<x_meshes; i++) {
for (int j=0; j<z_meshes; j++){
// Generate named gameobjects and make them children of bathyBoss object.
// It isn't strictly necessary to provide names for the GameObjects
// generated by the script, but, they show up in the hierarcy at run
// time so they look cleaner, and being able to find by name helps in
// clean up for regenerations and such.
string goname = System.String.Format("Bathy_{0}{1}",i,j);
Bathys[i,j] = new GameObject(goname);
Bathys[i,j].transform.parent = bathyBoss.transform;
Bathys[i,j].AddComponent<MeshRenderer>();
Bathys[i,j].AddComponent<MeshFilter>();
Bathys[i,j].AddComponent<ShowMeshVertices>();
Mesh bathy = new Mesh();
bathy.vertices = GenVertices ();
Bathys[i,j].GetComponent<MeshFilter>().sharedMesh = bathy;
// add a mesh collider for flythrough terrain avoidance
MeshCollider mshcol = Bathys[i,j].AddComponent(typeof(MeshCollider)) as MeshCollider;
mshcol.sharedMesh = bathy;
// position mesh's gameobject for correct overlap
/*
ij
10 | 11
---+---
00 | 01
*/
// float x_off = ((float)i)*x_cells;
// float z_off = ((float)j)*z_cells;
float x_off = fi*(float)x_cells; // need some work for other than 1.0 sizes
float z_off = fj*(float)z_cells;
// WHAT IN THE...?!! CAN'T MAKE A FLOAT HERE...
Debug.Log("x_off " + i + " = " + x_off);
Debug.Log("z_off " + j + " = " + z_off);
Bathys[i,j].transform.position = new Vector3((float)x_off,0f,(float)z_off);
fj++;
}
fi++;
fj=0;
}
}