Hello, everyone!
Please help with your next problem.
I have a tilemap on which a player can move by mouse click. I also made scriptable objects for different types of tile. For example, a cave tile has a name and a description. I want to make it so that when a player moves to this tile, the name and description will appear on the screen. How can you implement this?
You could probably just use a raycast down from the player which returns the first GameObject’s name it comes in contact with. Do your raycast then something like hit.collider.gameObject.name.
Check this thread for something similar:
One option is to create a custom class inheriting from Tile, which has fields to define this new data. Then you can make one of these custom tile assets for each tile, and assign the data in the assets inspector. Then at runtime, you can use GetTile to retrieve the tile as a TileBase, and cast it to your tile type to access the data.
That option has the downside that there’s currently no way to automatically create custom tile types when dragging sprites into the palette, Unity will always create the default Tile, so you will need to manually create each new tile one by one, via the Create menu entry added by the [CreateAssetMenu] attribute at the top of the custom tile class. See these examples:
Another option is to make the data accessible outside the tiles, and create a scriptable object or some other accessible class which contains a mapping of Tile to TileInfo. When the player lands on a tile, use GetTile, and then retrieve the TileInfo from the map based on which Tile asset was retrieved.