So I’m trying to keep track of the player’s current cell position, using the below code. Everything was working fine until I copied over my code to a new script. I checked transform.position and it is returning the correct position every update. I’m not sure if there is an issue with referencing the Tilemap when I switched over to the new script. I drug my Ground Tilemap–which is the child of Tilemap Grid-- to the project window to create a prefab, then drug that prefab into the reference of my Player Behavior script. This was the only way I found to get a reference to a component of the right type, although when clicking the bullseye it says there are no Tilemaps in my project.
public Tilemap groundTilemap; //Get reference to ground tilemap
void Update()
{
currentCell = groundTilemap.WorldToCell(transform.position); //Update cell location of player
}