Created
September 3, 2023 11:03
-
-
Save Enigo/7dda5bd0a37f2240a0f25dd937a9f186 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 | |
{ | |
... | |
// make positive to achieve opposite layout | |
private const float Offset = -0.5f; | |
private const float HexDistance = 1.2f; | |
... | |
// set the Hex child to Y rotation = 30 | |
private void SetupColumnLayout() | |
{ | |
var rows = 5; | |
var columns = 5; | |
float x = 0f, z = Offset; | |
var hexes = new Dictionary<Vector2Int, GameObject>(rows * columns); | |
for (var column = 1; column <= columns; column++) | |
{ | |
for (var row = 1; row <= rows; row++) | |
{ | |
var positionInGrid = new Vector2Int(row, column); | |
var hex = Instantiate(Hex, new Vector3(x, 0, z), | |
Quaternion.identity, transform); | |
hexes[positionInGrid] = hex; | |
z += HexDistance; | |
} | |
z = column % 2 == 0 ? Offset : 0; | |
x += HexDistance; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment