private void SpawnHex(int x, int y) { float xPos = 0f; float yPos = SingleHexDimensions.y * 0.5f; // If x is odd, move down half hex more yPos += x * SingleHexDimensions.y; if (y % 2 == 1) { yPos += SingleHexDimensions.y * 0.5f; } xPos += y * SingleHexDimensions.x * 0.75f; // Keep map centered //xPos -= _xCount * 0.5f * SingleHexDimensions.x * 0.75f; //yPos -= _yCount * 0.5f * SingleHexDimensions.y; GameObject hex = Instantiate(_hexagonTile.gameObject, _hexMapParent, false); var hexTile = hex.GetComponent <HexTile>(); hexTile.MapImPartOf = this; hexTile.CoordinatesInMap = new Vector2(y, x); hex.transform.position = new Vector2(xPos, yPos); hexTile.TileColor = Random.ColorHSV(0, 1); // Position text WorldspaceText posText = GameController.Instance.Debug.GetWorldSpaceText(hex); posText.SetText($"{y},{x}"); posText.transform.position = hex.transform.position; _spawnedHexObjects.Add(hexTile); }
public WorldspaceText GetWorldSpaceText(Object caller) { GameObject obj = Resources.Load <GameObject>("DebugPanel"); GameObject inst = Instantiate(obj); inst.transform.SetParent(transform); WorldspaceText wst = inst.GetComponent <WorldspaceText>(); wst.SetOwner(caller); return(wst); }