- Home /
How to access a texture2d from another scene
Hi, I have one scene where I have multiple 2d textures in an STATIC array called "applicationTexts". I am trying to check in another scene if a certain texture is contained at a certain index. For example :
SquadSelect.applicationTexts [0] == Resources.Load("louis_f")
This seems to work, but im afraid if I port to Android or iOS it will not recognize the directory. Ive tried making the textures Static by using :
public static Texture2D ExampleImageIcon = null;
but it wont show up when I am in the inspector to allow me to apply an image
Doesn anyone know how to access a static texture from another class? Or if there is a safe way to house resources so that I can port to iOS or Android? Thanks,
Answer by Jaguar06 · Jul 17, 2014 at 03:28 AM
use the DontDestroyOnLoad(TARGET);, then that GameObject won't destroy when you load another scene.
and Resources folder is always contain that's sub-files when your build, you can access Resources.Load() or like this
fileName = _fileName;
#if UNITY_IPHONE
string fileNameBase = Application.dataPath;
filePath = fileNameBase + "/Resources/" + fileName;
#elif UNITY_ANDROID
filePath = Application.dataPath + "/Resources/" + fileName;
#else
filePath = Application.dataPath + "/Resources/" + fileName;
but it is unsuitable to load texture. use this when you load text or binary files.