Created
September 3, 2023 10:54
-
-
Save Enigo/91f32ffa4496690252373b18eca6263f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BoardCreator : MonoBehaviour | |
{ | |
public GameObject Hex; | |
// make positive to achieve opposite layout | |
private const float Offset = -0.5f; | |
private const float HexDistance = 1.2f; | |
private void Start() | |
{ | |
SetupRowLayout(); | |
} | |
private void SetupRowLayout() | |
{ | |
var rows = 5; | |
var columns = 5; | |
float x = Offset, z = 0f; | |
var hexes = new Dictionary<Vector2Int, GameObject>(rows * columns); | |
for (var row = 1; row <= rows; row++) | |
{ | |
for (var column = 1; column <= columns; column++) | |
{ | |
var positionInGrid = new Vector2Int(row, column); | |
var hex = Instantiate(Hex, new Vector3(x, 0, z), | |
Quaternion.identity, transform); | |
hexes[positionInGrid] = hex; | |
x += HexDistance; | |
} | |
x = row % 2 == 0 ? Offset : 0; | |
z += HexDistance; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment