Home Game Development 2nd – Removing partitions of a tilemap at runtime in unity

2nd – Removing partitions of a tilemap at runtime in unity

0
2nd – Removing partitions of a tilemap at runtime in unity

[ad_1]

I’ve been making an attempt to implement some mild procedural era into my sport, nothing fancy. Just spawning rooms down in numerous areas with a purpose to add some replayability. I watched a couple of movies and the prevailing knowledge appears to be creating room prefabs and putting them at factors on this planet which I’ve carried out.

Image of room prefab

Its at this level I wish to differ my implementation than these on-line, I wish to at runtime take away tiles on the North, South, East and west elements of the partitions like so.

Mock up of walls being removed from room

My fundamental drawback is making an attempt to determine the place these factors are within the tile map, I’ve tried creating empty sport objects and including them as youngsters to the Tilemap and taking their positions after which utilizing Tilemap.SetTile(baby.rework.place,null) to take away the tiles, nevertheless the tile that finally ends up being set is all the time fallacious and offset by a certain quantity, I’ve tried to make use of Tilemap.bounds and Tilemap.localbounds to attempt calculate the width and peak of the Tilemap with a purpose to get the midpoint between 0-width and 0-height however the bounds of the Tilemap is definitely approach greater than the area my tiles truly cowl on this planet, in order that’s additionally untenable. Using Tilemap.WorldToCell or Tilemap.LocalToCell additionally has not labored.

If that is unattainable, or simply far more sophisticated than its price, are there different methods for me to attract rooms at runtime that dont contain me creating a giant 2D of gameobjects with sprites and colliders as a result of that’ll simply tank my efficiency.

Heres the Code I’m utilizing to loop by means of all the kids of my Grid and test in the event that they include the proper tag (North South East West) after which utilizing that place to swap the tile

 void clearTiles(string dir){
    List<Transform> tiles = FindComponentInChildWithTag(this.gameObject,dir);
    foreach(Transform t in tiles){
        map.SetTile(new Vector3Int((int)t.place.x,(int)t.place.y,0),tile);
    }
}
    public static List<Transform> FindComponentInChildWithTag(GameObject mum or dad, string tag){
       Transform t = mum or dad.rework;
       List<Transform> youngsters = new List<Transform>();
       foreach(Transform tr in t)
       {
              if(tr.tag == tag) 
              {
                   Debug.Log(tr.identify + " " + tr.localPosition + " " + tr.place);
                   youngsters.Add(tr);
              }
       }
       Debug.Log("Children measurement " + youngsters.Count);
       return youngsters;
 }

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here