Hey guys,
I’m just starting out with unity and am making an Android app. So far I have a background and a tileMap object that draws a grid of Tiles on the screen. When I use the game preview in the scene window the tiles are drawn correctly, but when I ‘Build and Run’ to Android the background is drawn, but the tiles are not.
using UnityEngine;
using System.Collections;
public class tileMap : MonoBehaviour {
public Transform tilePrefab;
//Tilemap width and height
public int mapWidth = 9;
public int mapHeight = 20;
//2D array to hold all tiles, which makes it easier to reference adjacent tiles etc.
public Transform[,] map;
// Use this for initialization
void Start () {
//Load prefab "Grass" from "Resources/Prefabs/" folder.
tilePrefab = Resources.Load <Transform> ("Prefabs/Tile");
//If we can't find the prefab then log a warning.
if (!tilePrefab)
Debug.LogWarning ("Unable to find TilePrefab in your Resources folder.");
//Initialize our 2D Transform array with the width and height
map = new Transform[mapWidth, mapHeight];
//Iterate over each future tile positions for x and y
for (int y = 0; y < mapHeight; y++)
{
for (int x = 0; x < mapWidth; x++)
{
//Instantiate tile prefab at the desired position as a Transform object
Transform tile = Instantiate (tilePrefab, new Vector3 ((x - 5.59f) * 0.64f, (y - 9.51f) * 0.64f, 0), Quaternion.identity) as Transform;
//Set the tiles parent to the GameObject this script is attached to
tile.parent = transform;
//Set the 2D map array element to the current tile that we just created.
map[x, y] = tile;
}
}
}
//Returns a tile from the map array at x and y
public Transform GetTileAt (int x, int y)
{
if (x < 0 || y < 0 || x > mapWidth || y > mapHeight)
{
Debug.LogWarning ("X or Y coordinate is out of bounds!");
return null;
}
return map[x, y];
}
// Update is called once per frame
void Update () {
}
}