Array returning wrong values?

#pragma strict

var hexPrefab: GameObject;
private var worldWidth: float;
private var worldHeight: float;
private var spawnSpeed: float;
private var letters = new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D');
private var numbers = new Array('1','3','5','7','9','11','13','15','17','19','21','23','25','27','29');

function Start () {
	worldWidth = 3.89*30;
	worldHeight = 7.48*30*0.5;
	spawnSpeed = 0.01;



function Update () {


function CreateHex() {
	yield WaitForSeconds(spawnSpeed);
	for (var x: float = 0; x < worldWidth; x+=3.89) {
		yield WaitForSeconds(spawnSpeed);
		for (var y: float = 0; y < worldHeight; y += 7.48) {
			yield WaitForSeconds(spawnSpeed);
			var hex = Instantiate(hexPrefab); = letters[x/3.89].ToString() + numbers[y/7.48].ToString(); //naming
			hex.transform.position = new Vector3(this.transform.position.x + x, this.transform.position.y + y, this.transform.position.z);

Hello, I’m having a problem with using arrays to return values. In this code I’m trying to spawn a field of hexagons with 2 separate spawners while naming every individual hex that has spawned. Thus both would have this same code, except one would have even numbered rows and be positioned differently. The rows and columns of the hexes are like chess, with the bottom row being row 1 and the leftmost column being column a. Never mind the actual spawning though.

Problem is when naming the hexes (eg a1, f7), even though I’ve tested explicitly the values for both x and y, at certain instances the array still returns me the wrong value. For example, at the fourth column (x = 11.67), letters[x/3.89] should return ‘d’, but it still returns ‘c’ to me. I’ve checked countless times and the value of x and y are what they are supposed to be when naming the hex, but the array is always returning the wrong value. This also happens to the numbers in the name as well. Is it some obscure coding mistake I’m making or a bug on Unity’s side? I’m still relatively new so pardon me.


Try to round to int.