void SpawnObjects() { // To apply a proper scale, get as a reference the length of a diagonal in tile 0 (note the "false" argument which specifies the position is in local coordinates) float size = Vector3.Distance(hexa.GetTileVertexPosition(0, 0, false), hexa.GetTileVertexPosition(0, 3, false)); Vector3 scale = new Vector3(size, size, size); // Make it 50% smaller so it does not occupy entire tile scale *= 0.5f; // Spawn 50 objects for (int k = 0; k < 50; k++) { GameObject obj = Instantiate <GameObject> (spawnObject); // Move object to center of tile (GetTileCenter also takes into account extrusion) int tileIndex = Random.Range(0, hexa.tiles.Length); obj.transform.position = hexa.GetTileCenter(tileIndex); // Parent it to hexasphere, so it rotates along it obj.transform.SetParent(hexa.transform); // Align with surface obj.transform.LookAt(hexa.transform.position); // Set scale obj.transform.localScale = scale; // Set a random color (notice the use of material and not sharedMaterial so every cube can have a different color) obj.GetComponent <Renderer> ().material.color = new Color(Random.value, Random.value, Random.value); } }