- Home /
Fetching files from disk at runtime
Hi. I'm trying to add a "modding" feature to my strategy game by allowing players to use a jpg file as a map. To do this i put a sprite object in the center of the scene, and made a script that reads from a file in the user's desktop to the game. I am using Loadimage and a WWW with a relative filepath to get the file called "myMap.jpg", but keep getting a NullReference exception. After almost two days of research, I can't figure out why. Please enlighten me.
Here is the code:
void Start () {
map = gameObject.GetComponent <Sprite> ();
}
void Update () {
if (canLoad) {
if (Input.GetKeyUp (KeyCode.P)) {
StartCoroutine (GitMap ("file://" + Application.dataPath.Remove (20) + "/myMap.jpg"));
Debug.Log (www.url);
//This debug confirms that the filepath is the one I'm looking for
if (www != null) {
Debug.Log (www.bytes);
}
tex.LoadImage (www.bytes); //here is the problem.
map = Sprite.Create (tex, new Rect (0, 0, tex.width, tex.height), new Vector2 (0.5f, 0.5f));
}
}
IEnumerator GitMap (string PATH) {
www = new WWW (PATH);
yield return www;
}
Comment
Your answer
Follow this Question
Related Questions
How to stop gradient banding? 2 Answers
Images not importing when platform is ios? 0 Answers
Import from Softimage? 2 Answers
texture import error 0 Answers
www problem (get image) ???? 2 Answers