public void Update() { Ray ray = Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue()); if (hexGrid.TryRaycastHexGrid(ray, out Vector3 worldPosition) && flyingBuilding != null) { flyingBuilding.gameObject.SetActive(true); Vector3 CoordsOfCenter = HexMetrics.CalcCenterCoordXZFromHexCoordXZ(HexMetrics.CalcHexCoordXZFromDefault(worldPosition, hexGrid.MapData.cellSize), hexGrid.MapData); isAvailable = IsPossibleToBuild(flyingBuilding, HexMetrics.CalcHexCoordXZFromDefault(CoordsOfCenter, hexGrid.MapData.cellSize)); #region syncing data with building flyingBuilding.HexCoords = HexMetrics.CalcHexCoordXZFromDefault(CoordsOfCenter, hexGrid.MapData.cellSize); flyingBuilding.transform.position = CoordsOfCenter; flyingBuilding.SetTransparent(isAvailable); #endregion } }
private void OnDrawGizmos() { if (!Application.isPlaying) { return; } for (int x = 0; x < Size.x; x++) { for (int z = 0; z < Size.y; z++) { Mesh hexMesh = new Mesh(); hexMesh.vertices = HexMetrics.corners; int[] tris = { 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5 }; hexMesh.triangles = tris; hexMesh.RecalculateNormals(); Gizmos.color = Color.Lerp(Color.red, Color.green, damageSystem.Hp / damageSystem.MaxHp); Vector3 CenterCoord = HexMetrics.CalcCenterCoordXZFromHexCoordXZ(HexCoords, hexGrid.MapData) + new Vector3(HexMetrics.CalcCenterCoordXZFromHexCoordXZ(new Vector3(x, 0, z), hexGrid.MapData).x, 0, HexMetrics.CalcCenterCoordXZFromHexCoordXZ(new Vector3(x, 0, z), hexGrid.MapData).z); Gizmos.DrawMesh(hexMesh, 0, CenterCoord, Quaternion.identity, Vector3.one * hexGrid.MapData.cellSize); } } }