To allow my character to interact with his environment (hang on ledges, wall jump, etc.), I created a script to iterate through the entire TileMap of a level and attribute the correct collision detectors with the correct sprite by its name. Here’s an abbreviated look at the method calls I use to handle this
{
//_Tile.name is the name of the sprite, LedgeTiles is a list of sprites that can be ledges
for(int i = 0; i < LedgeTiles.Length; i++)
if (_Tile.name.Equals(LedgeTiles*.name))*
*return true;*
*return false;*
*}```*
*Currently, this is done with normal Tile Palettes and it works pretty well.*
<em>However, now I want to make map editing easier for iteration by using RuleTiles. The RuleTile itself is fine, but when that code checks _Tile.name, it returns the name of the RuleTile, not the name of the sprite the RuleTile is displaying. I want the name of the sprite the RuleTile is displaying. *Is there a way to determine which sprite is currently displayed by a RuleTile, and a way to determine if a tile at position x, y, z is a RuleTile object and not a regular TileBase object?*</em>
Well if you need to grab only a certain type of tile you can always use the
tilemap.getTile(Vector3int position) and if it is null there either no type of that tile or no tile at all at that position.
I have my characters jump on ledges, hang and so on but I don’t need to create the kind of script you are using. The tilemap just need a composite collider…
I use a composite collider for normal traversal, but for hanging onto ledges I only want the player to switch into the ledge-hang-state if their position is relative to the corner of a particular tile. The original method relied on manual calculations to determine the player’s proximity from the ledge tile upon contact with said ledge tile. I tried that before, actually, but I didn’t really do too well. So I went with 2D circle colliders instead.
I don’t use too many CircleCollider2Ds, though. I keep 16 and move them to other positions when the player-character moves between subdivisions of the map. I was just providing that as a context to my problem. Whether or not I use colliders or run manual calculations (to detect proximity to ledges) wouldn’t matter if I don’t know which sprite was a ledge tile.