Hello,
I am making a tile based spaceship simulation game like FTL.
This model has been created by script.
(This is a flat map. Some tiles has different sizes or shapes).
Here is my Code;
using System.Collections.Generic;
using UnityEngine;
public class TestData : MonoBehaviour {
int[,] tile;
public int mapSizeX;
public int mapSizeY;
public List<TileType> tileTypes;
void Start()
{
tileTypes = GameObject.Find("Database").GetComponent<Database>().tileType;
tile = new int[mapSizeX, mapSizeY];
for (int x = 0; x < mapSizeX; x++)
{
for (int y = 0; y < mapSizeY; y++)
{
tile[x, y] = 0; //Fill the map with non-prefab tile(This is for another thing, will be not generated)
}
}
GenerateTileData();
GenerateTiles(mapSizeX,mapSizeY);
}
void GenerateTileData()
{
int x, y;
//Room_1
for (x = 3; x <= 6; x++)
{
for (y = 9; y <= 14; y++)
{
tile[x, y] = 7;
}
}
tile[18, 10] = 3;
tile[19, 10] = 3;
tile[18, 13] = 3;
tile[19, 13] = 3;
tile[15, 4] = 3;
tile[15, 19] = 3;
//Room_2
for (x = 8; x <= 10; x++)
{
for (y = 9; y <= 14; y++)
{
tile[x, y] = 8;
}
}
//....so much more like this
}
void GenerateTiles(int sizeX, int sizeY)
{
for (int x = 0; x < sizeX; x++)
{
for (int y = 0; y < sizeY; y++)
{
if (tile[x, y] != 0)
{
GameObject go = Instantiate(tileTypes[tile[x, y]].tileObj, transform);
go.transform.localPosition = new Vector3(x, y, 0);
TileData td = go.GetComponent<TileData>();
td.testmapper = this;
}
}
}
}
}
I want to make different ships.
More ships means need thousands of “tile[x,y] = a”
I want to store this data in somewhere and script should access when creating ship models.
I tried jsonMapper for this but i could not
Anybody have an idea for this ?
Sorry for my english if i wrote something wrong.