Best way to select a tile in a tilemap

Hi, I’m trying to wrap my head around using the new tilemap system.

As the screen shot alludes to, I am trying to be able to select any single tile when a user clicks on it. I’m wondering what the best way to do this is. I’ve tried using the EventSystem and OnMouseDown(), but neither do anything the way I’ve done it.

You have a bunch of options, depends exactly what you’re trying to achieve.

An easy way, assuming the game will only be 2 dimensional, is to create a giant collider object. When the user clicks, use a Raycast and camera.ScreenPointToRay to scan for a hit on the collider.

When (if) you get a hit on the collider, get the hit.point of the collision and use Mathf.Round to get the closest whole number in the 2 axis that your world is created in. This will give you a reference to where in the world the user just clicked. From there you can reference that against your array of tiles or however else you are storing their information.

I’ve been grappling this same issue recently and what I decided to do was just use the tilemap as a blueprint to generate prefab tiles. Prefabs are easy to click on, tack scripts onto, etc. Tiles not so much.