- Home /
Question by
HerryChoding · Jan 05, 2018 at 04:08 AM ·
c#androidinstantiate prefab
Instantiated Tiles get positioned randomly on android devices
I'm trying to make a tower defense 2D for Android, as I make the map with the instantiated tiles on prefabs, it worked perfectly on UnityEditor but once I import it to Android the tiles went out of the camera bounds like this
I made my Map Tiles like this
private void CreateLevel()
{
Tiles = new Dictionary<Point, TileScript> ();
string[] mapData = ReadLevelText ();
mapSize = new Point (mapData [0].ToCharArray ().Length, mapData.Length);
int mapX = mapData [0].ToCharArray ().Length;
int mapY = mapData.Length;
Vector3 worldStart = Camera.main.ScreenToWorldPoint (new Vector3 (0, Screen.height));
for (int y = 0; y < mapY; y++)
{
char[] newTiles = mapData [y].ToCharArray ();
for (int x = 0; x < mapX; x++)
{
PlaceTile (newTiles[x].ToString(),x,y,worldStart);
}
}
SpawnPortals ();
}
private void PlaceTile(string tileType, int x, int y, Vector3 worldStart)
{
int tileIndex = int.Parse (tileType);
TileScript newTile = Instantiate (tilePrefabs[tileIndex]).GetComponent<TileScript>();
newTile.Setup (new Point (x, y), new Vector3 (worldStart.x + (TileSize * x),worldStart.y - (TileSize * y), 0), map);
Tiles.Add (new Point (x, y), newTile);
}
I wonder if anyone has solution on this, I tried any way that I could do but the instantiated tiles(prefabs) seems to stuck at upper screen like the picture...
Comment