I am using Unity to program a simple Android game in C#. Right now, all the game does is to randomly load one of 196 flags upon startup (view: https://hastebin.com/suxonayoce.cs or code below). This class file is currently the only class file there is. When I play the game in Unity everything works as expected (i.e. each time the game is started a random flag is displayed). However, when I build and run the game on my Android phone only the placeholder flag is displayed and never a randomly chosen one.
So far I've tried relaunching Unity, re-importing all assets, and recreating the game in a new project. Nothing of this has resolved the problem.
using System.IO;
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
private int _flagCount = 196;
private string[] _ccTlds;
private void GenerateCctldsArray()
{
_ccTlds = new string[_flagCount];
_ccTlds = File.ReadAllLines(@"Assets\ccTLDs.txt");
}
private void DisplayRandomFlagSprite()
{
// Randomly gets the file name of a flag.
int flagArrayPosition = Random.Range(0, 195);
string flagImageName = _ccTlds[flagArrayPosition];
// Gets the sprite of the flag called "flagName".
Sprite sprite = Resources.Load<Sprite>(@"FlagSprites\" + flagImageName);
// Loads the image associated with "flagName".
FlagImage.GetComponent<Image>().sprite = sprite;
}
[SerializeField]
private GameObject _flagImage;
public GameObject FlagImage
{
get { return _flagImage; }
set { _flagImage = value; }
}
private void Awake()
{
GenerateCctldsArray();
DisplayRandomFlagSprite();
}
}
Does anyone have any ideas why the games stops working when it is run on the phone and how this can be fixed?