Change Single Tile Depending on Amount of Damage

Updated on February 22, 2018 in [A] 2D
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on February 21, 2018

I’m making a game where you have a Bulldozer and you have to crash into walls and they break after 3 or so hits. The walls and ground are tiles. I can get each wall tile hit, to change to a cracked wall sprite with some issues from offsetting it. I just can’t figure out how to make it change to another sprite after the next hit, and then break on the 3rd hit. I’ll post my bulldozer script below, that is doing the tile changing. I left out the movement parts of the script to slim it down. Thanks in advance.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Tilemaps;
public class Bulldozer : MonoBehaviour {
   public GameObject destructableTilemap;
   Tilemap tilemap;
   public Tile borderTile;
   public Tile destructableTile;
   public Tile crackedTile;
   // Use this for initialization
   void Start () 
      if (destructableTilemap != null)
         tilemap = destructableTilemap.GetComponent<Tilemap>();
   void OnCollisionEnter2D(Collision2D col)
      Vector3 hitPosition =;
      if (tilemap != null && col.gameObject == destructableTilemap)
         foreach (ContactPoint2D hit in col.contacts)
            hitPosition.x = hit.point.x - 0.01f * hit.normal.x;
            hitPosition.y = hit.point.y - 0.01f * hit.normal.y;
            tilemap.SetTile(tilemap.WorldToCell(hitPosition), crackedTile);


  • Liked by