Hello, I am working on a mobile platformer game, which going to have a lot of levels. So I decided to find a way where I could draw the level, and base on the color of the pixels a certain prefab would spawn in at that spot. So I used quill18’s script, which suited my needs perfectly Unity Tutorial: Fast & Easy Level Editor Technique for Platformers and RPGs! - YouTube
So this works just fine in the Editor, but once I test it on my android phone, the map doesn’t load. So I’m unsure as to why it can’t find the image. I’m placing the images in a StreamingAssets folder as well.
public void LoadMap()
{
EmptyMap();
manager.currentLevel += 1;
levelFileName = manager.levels[manager.currentLevel].levelString;
// Read the image data from the file in StreamingAssets
string filePath = Application.streamingAssetsPath + "\\" + levelFileName;
byte[] bytes = System.IO.File.ReadAllBytes(filePath);
Texture2D levelMap = new Texture2D(2, 2);
levelMap.LoadImage(bytes);
// Get the raw pixels from the level imagemap
Color32[] allPixels = levelMap.GetPixels32();
int width = levelMap.width;
int height = levelMap.height;
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
SpawnTileAt(allPixels[(y * width) + x], x, y);
}
}
}
Any help at all would be greatly appreciated!