Hiya, I am working on recreating a game similar to club penguins Thin Ice minigame, which is a 2D maze game for my coursework for college. This is my first time using C# and unity so I am very much learning as I go along. In my game I have a player that moves around a maze which is made out of two tilemaps, one for the walls and one for the walkable ground (which is made up of a light blue tile which is meant to represent ice) , once the player has moved over a tile, the ice tile is supposed to melt into a water tile, so all I am trying to do is change the tile to a different one once the player has walked over the ice tile. Here is my script (which is attached to the ground tilemap and the tilemap has a rigidbody 2D component and a tilemap collider 2D with isTrigger ticked, player also has a box collider and rigidbody 2D). Any help would be appreciated greatly
void Start()
{
//Finds positions of tiles on animated Ground tilemap
Tilemap AnimatedGround = GetComponent<Tilemap>();
BoundsInt bounds2 = AnimatedGround.cellBounds;
TileBase[] allTiles2 = AnimatedGround.GetTilesBlock(bounds2);
for (int x = 0; x < bounds2.size.x; x++)
{
for (int y = 0; y < bounds2.size.y; y++)
{
TileBase tile = allTiles2[x + (y * bounds2.size.x)];
if (tile != null)
{
//if there is a tile adds the position to a list
Debug.Log("x:" + x + " y:" + y + " tile:" + tile.name);
pos.x = x;
pos.y = y;
listOfTilePositions.Add(pos);
}
}
}
}
void OnTriggerExit2D(UnityEngine.Collider2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
//iterates through the list to see what tile the player is on
for (int i = 0; i < listOfTilePositions.Count; i++)
{
if (listOfTilePositions[i] == playerPosition)
{
Vector3Int tilePos = AnimatedGround.WorldToCell(listOfTilePositions[i]);
_ = AnimatedGround.GetTile(tilePos);
AnimatedGround.SetTile(tilePos, null);
AnimatedGround.SetTile(tilePos, spritesheet_5);
}
// }
}
if (collision.gameObject.CompareTag("Wall"))
{
collision.isTrigger = false;
}
}
}
}