- Home /
Cant load image into my game
Hey, I want to import an image at runtime into my game from a folder. There is a button, which opens the Editor Utility Open Folder Dialog so you can choose the folder where an image with the name "1 - mid" must be inside. After Choosing the Folder, the image "1 - mid.*" will be added on a new plane. To import the image to the plane I'm using the following code:
using UnityEngine;
using System.Collections;
using System.IO;
using UnityEditor;
using UnityEngine.UI;
namespace ImportClass {
public class ImportPack : MonoBehaviour {
IEnumerator LoadTexture (FileInfo newPath)
{
WWW www = new WWW ("file://"+newPath);;
yield return www;
Texture NewImage = null;
ButtonGameObject.GetComponent<Renderer>().material.mainTexture = www.texture;
}
}
}
Actually everything works fine when I start use this. But when I choose the Folder to import, it shows a questionmark image on the Plane...
This is the actual image that I want to show ingame...
Can someone tell me why it shows the questionmark instead of the chosen image?
Answer by komodor · Jun 28, 2015 at 07:40 AM
i'd say the problem is in this line
WWW www = new WWW ("file://"+newPath);;
where you are adding FileInfo to the string
sorry for delay
newPath is FileInfo and not a string, so the FileInfo.ToString() is automatically called and maybe it's not the rest of the path
That worked for the most of the pictures but some of them still show that question mark...
Your answer
Follow this Question
Related Questions
texture import error 0 Answers
[Edited]Access photos from gallery in application (Android) 1 Answer
Mesh deformed? Tried re-import... 1 Answer
import blend to unity, rig look mess 0 Answers
Import Image from Library 0 Answers