- Home /
2D Tiles and sprites
I plan to create a 2D (2,5D) isometric game similar to old fallouts. I've got most of the code figured out, the only thing I don't know is how to visualize everything for the player. Levels/maps are supposed to be hex tiles, although rectangle/square tiles aren't bad either. As far as I know there are two ways to display content to the player - via game objects and GUI. I tried both ways and neither is sufficient for my needs.
Gameobjects: I made hex models in 3ds max and made my sript instantiate them for each field of my array
using UnityEngine;
using System.Collections;
public class HexGrid : MonoBehaviour {
private const int MAP_H = 50;
private const int MAP_W = 50;
public static int[,] map;
private GameObject hex;
void Start () {
map = new int[MAP_H, MAP_W];
hex = Resources.Load("Prefabs/hex") as GameObject;
for(int i = 0; i < MAP_H; i++)
{
for(int j = 0; j < MAP_W; j++)
{
Vector3 coords;
if(i % 2 == 0) coords = new Vector3(j * 3, 0, (i / 2) * -1);
else coords = new Vector3(1.5f + j * 3, 0, 1 + (i / 2) * -1);
GameObject go = new GameObject();
go = Instantiate(hex, coords, hex.transform.rotation) as GameObject;
go.name = i.ToString() + " " + j.ToString();
}
}
}
}
I also have a camera control script which allows me to move it around to see all the map. Sadly this is merely 50x50 field map and it already loads very long and I'm going to need something bigger, not to mention everything that's going to appear over the map (houses etc).
GUI: I tried the same thing using GUI.Buttons, sadly I can only have square buttons, can't rotate them.
What I need is an alternative way to display tiles, and way to check if mouse is over them (and I mean exactly over the pixels, not the empty area of the rectangle). Alternatively I need an advice on how to handle this problem
Answer by Sammual12 · Feb 23, 2012 at 05:46 PM
A large number of 3D Hex tiles is slow. (At least the ways I have tried it) If your hex tile can be flat you are better off creating a procedural (hexagon) mesh and using texture atlas with all your Hex Tertures in it.
http://answers.unity3d.com/questions/25067/setting-custom-uv-mapping.html
Other options are;
Tasarran's HexTech - http://forum.unity3d.com/threads/102511-HexTech-Hexagon-Tile-Based-Map-Framework-available-on-Asset-Store
ForceX's FX Hex Grid - http://forum.unity3d.com/threads/107656-FX-Hex-Grid-(Hex-Grid-Generator)