Вот код создания карты:
Код: Выделить всё
// Makes the map and assigns the data to tileInfo, done in Start()
tileInfo = new Dictionary();
tilemap = GetComponent();
gameObject.transform.position = new Vector3(-mapsizex / 2, -mapsizey / 2, 0);
for (int x = 0; x < mapsizex; x++)
{
for (int y = 0; y < mapsizey; y++)
{
tilemap.SetTile(new Vector3Int(x, y, 0), tileMain);
tileInfo.Add(new Vector3Int(x, y, 0), tileMainData);
}
}
// I add other blocks in a different snippet of code, but it does the same thing
< /code>
И вот код, который меняет значения: < /p>
// Runs when you click a tile, in Update()
void HitTile(Tile brokentile, TileData brokentiledata, Vector3Int cellPosition)
{
TileBase crnttile = tilemap.GetTile(cellPosition);
if (tileInfo[cellPosition].health > 1)
{
tileInfo[cellPosition].health -= 1;
}
else
{
tilemap.SetTile(cellPosition, brokentile);
tileInfo.Remove(cellPosition);
tileInfo.Add(cellPosition, brokentiledata);
}
}
Есть ли способ изолировать значение словаря из его входов? Я хотел бы установить работоспособность в экземпляре, а затем, когда он будет назначен словарю, значение в словаре не будет связано с экземпляром, чтобы при изменении значения в словаре экземпляр оставался в покое.
Подробнее здесь: https://stackoverflow.com/questions/793 ... assigns-it
Мобильная версия