Unity is giving me an error in regards to my float array. Its expecting int even though i set the array as float. There is an image i uploaded of the error. Thank You
public class SphereChunk : MonoBehaviour {
public float[,,] map;
public Mesh visualMesh;
protected MeshRenderer meshRenderer;
protected MeshCollider meshCollider;
protected MeshFilter meshFilter;
// Use this for initialization
void Start () {
meshRenderer = GetComponent<MeshRenderer> ();
meshCollider = GetComponent<MeshCollider> ();
meshFilter = GetComponent<MeshFilter> ();
float width = 10/SphereWorld.currentSphereWorld.radius;
map = new float[0.1f, 10f, 0.1f];
for (float x = 0; x < width; x+= SphereWorld.currentSphereWorld.polar) {
for (float y = SphereWorld.currentSphereWorld.radius; y < World.currentWorld.chunkHeight + SphereWorld.currentSphereWorld.radius; y++) {
for (float z = 0; z < width; z+= World.currentWorld.chunkWidth * SphereWorld.currentSphereWorld.polar) {
float a = y * Mathf.Cos(SphereWorld.currentSphereWorld.elev);
x = a * Mathf.Cos(SphereWorld.currentSphereWorld.polar);
y = y * Mathf.Cos(SphereWorld.currentSphereWorld.elev);
z = a * Mathf.Cos(SphereWorld.currentSphereWorld.polar);
map[x, y, z] = 1;
Debug.Log("X is : " + x + " Y is : " + y + " Z is : " + z);
}
}
}
}
You can convert from float to int by several techniques.
Each of these has different behaviours:
float myFloat = 4.5f;
int x;
x = (int)myFloat; // casting will round toward zero
x = Mathf.FloorToInt(myFloat); // floor will round to the low value
x = Mathf.RoundToInt(myFloat); // round will round to the closest value
x = Mathf.CeilToInt(myFloat); // ceiling will round to the high value
You will need to decide which is appropriate for your circumstances.