I’m new to Unity and trying to code a script which generates a 2D hex map (Battle Isle style). I’ve understood how the coordinates of a hex grid work but I’m unable to create one and set sprites at those positions. After the generation process has finished I want to set properties to the generate hexes.
How do I do that?
EDIT: I should add that I’m very unskilled using search functions, most of stuff I get out of them is useless for me >.<
there are at least 2 grid managers in the asset store. there is a hexgrid implementation of user forcex free available. but it uses gameobjects as single hexes what gets quite large amounts quickly. so if you aim for large maps it will not suit you.
if you don’t mind using dx11 you can use this as base to place a hex on each vertex of a mesh you feed in. as a unity mesh can hold 65k vertices you can have a circular grid with radius of around 145.
if you want to succeed in programming this is what you must change with priority. if you can’t use all the resources in the web for your advantage you will have a hard time. the forum cannot replace your own efforts.
you must be a little more specific when you want specific help.
this is usually done by making a hex a class. then you can let it contain an enum for the terrain type, a list of units/buildings, special “effects” etc… and interpret this map to display your world.
you could use an ordinary 2d array to hold your hexes. however, i had implemented a dictionary to hold the hexes which are indexed by their 3 axis coordinate. but this requires quite some math to calculate the positions etc.
so if you are a beginner with programming this is definitely not the topic to learn with. do some tutorials and return to your project when you have a solid understanding of general programming concepts. usually you also will understand documentation better then. but without enough experience you are lost.
Edit: i forgot, there is also a turn based toolkit in the asset store. maybe a good start when you aim something battle isle like. it also uses hexes.
I’m not completely new to programming, just to Unity and its structure as well as the whole graphics stuff.
I actually want to do it from scratch. And since I have no clue of dx whatsoever I’ll stick around with game objects.
I want to create a game board of hexes (rectangular shape, axial coordinates). I’m working in 2D and with sprites for hexes.
After reading some stuff regarding hexagons I first want to know how to store my map properly. After that things like placing game objects and simple distance calculation shouldn’t be too hard (are they?)
Tried to use something like that before opening this thread and failed. Guess my code was just bad xP