- Home /
Assistance Request: Dynamic Tilemapping
Search Engines have failed me in looking for the answers I need. My issue is a CS0122 Inaccessible due to protection. the objective is to have 1 line place all of the tiles on a tilemap based on data from a list.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;
public class Game_Supplies : MonoBehaviour {
//Serialization Inputs
public Map_Data _MapData;
public Tile_Sets _TileSets;
public Object_Sets _ObjectSets;
public Monster_Sets _MonsterSets;
public NPC_Sets _NPCSets;
//Tile List Sets
public List<AreaData> AD = new List<AreaData>();
public List<TileData> TD = new List<TileData>();
//Tile Placement Sets
public int _TCount;
public int _TPlaced;
public Vector3Int _Position;
void Start(){
GenBaseMap();
TD.Add(new TileData(new Vector3Int(0, 0, 0), "_Ground", "_GroundField"));
}
void GenBaseMap(){
_TCount = TD.Count;
for(_TPlaced = 0; _TPlaced < _TCount - 1; _TPlaced++){
Vector3Int _TilePos = new Vector3Int(TD[_TPlaced].Data_TilePos.x, TD[_TPlaced].Data_TilePos.y, 0);
string _LayerName = TD[_TPlaced].Data_TileLayer;
string _TileType = TD[_TPlaced].Data_TileType;
//needs modification for variance
//_TileSets._TileLayer._Ground.SetTile(_TilePos, _TileSets._RuleTiles._Ground_Field);
_TileSets._TileLayer(_LayerName).SetTile(_TilePos, _TileSets._RuleTiles._Ground_Field); //Error is in this line "TileLayer(_LayerName)".
_TPlaced++;
}
}
public class TileData {
public Vector3Int Data_TilePos;// Store the location of the area center
public string Data_TileType; // tile type from "Rule_Tiles"
public string Data_TileLayer; // tile layer from "Tile_Layers"
public TileData (Vector3Int _TPos, string _TType, string _TLayer) {
Data_TilePos = _TPos;
Data_TileType = _TType;
Data_TileLayer = _TLayer;
}
}
[Serializable]
public class Tile_Sets {
public Rule_Tiles _RuleTiles;
public Tile_Layer _TileLayer;
}
[Serializable]
public class Rule_Tiles {
public RuleTile _Ground_Field;
public RuleTile _Ground_Forest;
public RuleTile _Ground_Town_1;
public RuleTile _Ground_Town_2;
public RuleTile _Ground_Town_3;
public RuleTile _Ground_Dun_1;
public RuleTile _Ground_Dun_2;
public RuleTile _Ground_Dun_3;
public RuleTile _Ground_Boss;
[Space(5)]
public RuleTile _Wall_Field;
public RuleTile _Wall_Forest;
public RuleTile _Wall_Town_1;
public RuleTile _Wall_Town_2;
public RuleTile _Wall_Town_3;
public RuleTile _Wall_Dun_1;
public RuleTile _Wall_Dun_2;
public RuleTile _Wall_Dun_3;
public RuleTile _Wall_Boss;
}
[Serializable]
public class Tile_Layer {
public Tilemap _Barrier;
public Tilemap _Ground;
public Tilemap _GroundOverlay;
public Tilemap _Obsticles;
public Tilemap _ObsticlesOverlay;
}
}
I have attempted several other methods of trying to get the _TileLayer to locate an item from the Tile_Layer class that matches the string of the input but nothing I have tried is working. The line above it tested just fine when explicitly pointing to "_Ground", but I would prefer the line to be dynamic. the same would be true for "_GroundFields" in that same line, but I'm sure solving 1 issue will solve the other.
Your answer
Follow this Question
Related Questions
I am following a tilemap tutorial, however the UV layout is strange. How can I fix this? 0 Answers
Should I use built-in tilemaps or create my own tilemap system? 1 Answer
How to build a tilemap at runtime? 1 Answer
How can I make tiles move for a dynamic background 0 Answers
Stop player from pushing tilemap 1 Answer