Here’s my situation. When each of my game scenes starts, it loads an image as a texture, and three scripts immediately need access to this texture or else they break. (They need information about the aspect ratio of the image in Start() ). To get this to work, a PuzzleStarter in each scene calls the GameController (a singleton that appears in every scene)'s GetImage() function. This loads the image into a texture called tex in the GameController, and then the coroutine passes control back to the PuzzleStarter’s StartPuzzle() function which uses SetActive() to turn on the three scripts. These scripts then call GameController.GC.tex to access the texture data. This is what that looks like, a bit simplified:
public class GameController : MonoBehaviour
{
public Texture2D tex;
void Awake()
{
tex = new Texture2D(1, 1);
}
public void GetImage()
{
string url = System.IO.Path.Combine(Application.streamingAssetsPath, "image.jpg");
WWW www = new WWW(url);
StartCoroutine(LoadTextureIntoImage(www));
}
IEnumerator LoadTextureIntoImage(WWW www)
{
yield return www;
if (www.error == null)
{
byte[] bytes = www.bytes;
tex.LoadImage(bytes);
GameObject.Find("PuzzleStarter").GetComponent<PuzzleStarter>().StartPuzzle();
}
}
}
My problem is that one of the scripts requiring the image/texture’s aspect ratio is the camera. So when I first start a scene with the camera deactivated, there is a weird momentary flicker during the texture load where my GUI canvas (which is scaled to fit the camera) spazzes out. So I’m thinking I need some sort of loading screen to allow the image to get loaded into the texture before the other scripts start. Any advice on how I can implement this?