Building a Simple Game in Unity with Hexasphere

Kronnect recently released a new asset on the Unity Asset Store called Hexasphere Grid System. I thought it was a cool asset and I had an idea (with the help of James Sterrett) for a simple game, so I asked to give it a try.

The concept of the game is two players compete to pick a path of hexes, on a sphere, that connect on opposite sides. Think of it as connecting a path from the North Pole to the South Pole. Players pick their starting hex from anywhere on the sphere. Players can then only claim a hex that is adjacent to an hex they’ve already claimed.

What was great was that almost all of the functionality I needed was there out-of-the-box.

To start, the player would click on a hex. This was easy because there is:

OnTileClick(tileIndex): if used, this event will be triggered each time a tile is clicked.

I then needed to set the color of the tile to that of the player (red or blue):

SetTileColor(tileIndex, color, temporary): like SetTileMaterial but it only assigns a color. An internal cache of materials is used to optimize draw count.

When a player attempted to claim a hex, I needed to check to see if it was next to a prior claimed hex. Kronnect kindly (and quickly) added:

GetTileNeighbours(tileIndex): gets all neighbours indices of a given tile.

Since the polar opposite of any claimed tile was a valid endpoint for the path, I requested and was happy to receive:

GetTileAtPolarOpposite(tileIndex): gets the tile index at the exact opposite pole position.

That was what I needed to build the alpha version. I’ll keep posting updates as the game is polished and eventually released (for free).

The associated code so far (remember, alpha code!!!)

Leave a Reply

Your email address will not be published. Required fields are marked *