Relative Content

Tag Archive for c#unity-game-enginedebuggingvector2

Float values get rounded creating a Hex Grid in Unity

My code generates a grid with a specified width and height and Instantiates a “hexTilePrefab” at the calculated floating point positions. The prefab has a class “HexTile” attached to it. Within HexTile “TileCoordinates” is defined as:
public Vector2 TileCoordinates { get; set; }
As seen in the comments of my code, assigning the directly by using a new Vector2() rounds the coordinates. As an example view image 2, where the coordinates are x=0.5 and y=0.86, but the code produces x=1 and y=1. Only if I assign the x and y values separately to a vector and then assign that vector to the coordinates, they are not rounded and are correctly established.