How to detect what tile player is standing on in a tile-based game

I have spent two days on this problem and still cannot figure it out. I am trying to make the character slide across oil but I am having an issue with detecting whether he is on oil or not. It is a 2D game and therefore all game elements are 0 on the z-axis so Raycasts wont work. I have also tried determining by using the player co-ordinates to determine what tile the player is on but due to the movement system, the player isn’t exactly always on a tile which is an exact multiple of 1. Any help or advice will be appreciated.

As there is an issue with a multiple of 1 you would simply round down the players position.

For example: if the players position of x is 25.5 then you know he is on tile 25

tileNumber = MathF.FloorToInt(Player.position.x);

This could be accompanied by an integer array of all the oil tiles

int [] oilTiles= new int[]  {25,26,27};

A simple check can then be carried out to decide whether the player is on an oiled tile or not


You can add trigger on tiles with oil. Create any static variable in your desired class . Set variable to true when you enter the tile with oil and set it to false when you leave it (Use onTriggerEnter and onTriggerExit ).