- Home /
How to draw a line around a hexagon
Hey so I'm creating a game with a hexagon map where you can build buildings but how do I make so there come a line around every single hexagon so I can see where I can build?
Answer by LilGames · Jul 03, 2019 at 07:27 PM
GameObject -> 2D Object -> Tilemap
Set it to Hexagon type of map
Okay, that helped but I wasn't clear I meant when I play the game there is a building mode how do I make so there comes a line around the hexagon?
I would just draw a sprite or texture of an outline and use that centered to the tile center. (Not everything has to be done "through program$$anonymous$$g", if you know what I mean.)
Yeah I know what you mean I just thought it would be easiest to make it so when you go into building mode it creates a line around the hexagon because you are not always in building mode
Answer by Optrix · Jul 04, 2019 at 03:47 AM
If your world is FLAT, it's actually pretty easy.
Make a texture with a repeating grid of hexagons (you can probably find some tutorials on how to do it online, or even grab a pre-made one). Make sure the background is transparent. Ideally, the colour of the hexes should be white (if it's black, you can invert the colours).
Add a 3D 'Plane' to your scene and place it just above your ground plane.
Create a new material for the plane, and use the texture you created earlier, making sure it's transparent. I usually use one of the Alpha Blended particle shaders for this rather than the standard shader.
Assign the material to your plane, and then you're ready to go. You can adjust the tiling of the texture until it matches the size of your game tiles. If your texture was white, you can adjust the colour in the material, which is handy (it's easy to make it green, red etc.).
The joy of this is that you get a huge number of hexes for just two triangles.
If you want to then light up a single hex, you use a much smaller plane that is exactly one hex grid across and has a texture with just the single hex.
If your world is not flat, that's a different thing all-together. I'd be very tempted to do it with a custom shader in that case.
Your answer
Follow this Question
Related Questions
LineRenderer Lines Have Inconsistent Widths 2 Answers
Line between main camera and background image 0 Answers
Draw Puzzle Lines Like Hitman Go Game 1 Answer
How to detect a mouse click on a line in 3d? 0 Answers
How to drag and drop lines in-game 1 Answer