- Home /
How to set a Texture from an External Folder.
Hi Guys! Im working in something. The Idea its pretty simple, the user will load and texture for an especific object. Im Using UnityEditor to get the path, and im stored it in a Stirng. Somehint like this:
using UnityEngine;
using UnityEditor;
using System.Collections;
public class LoadContent : MonoBehaviour {
string path;
void Start () {
}
void Update () {
}
void OnMouseDown(){
path = EditorUtility.OpenFilePanel("Overwrite with png", "", "png");
Debug.Log(path);
StartCoroutine (LoadImageAsTexture (path));
}
IEnumerator LoadImageAsTexture(string sPath){
WWW www = new WWW (sPath);
yield return www;
Texture2D texTmp = new Texture2D (256,256);
www.LoadImageIntoTexture(texTmp);
this.renderer.material.SetTexture ("_MainTex", texTmp);
}
}
But it doesnt work, mi Quad isnt changing Texture.
I Hope you could help me guys. Thnks!!!
Answer by HarshadK · Nov 25, 2014 at 07:47 AM
Since you are using local file from device itself you need to prepend **file:///** to your path.
WWW www = new WWW ("file:///" + sPath);
Thanks a lot! Im new in all of this using Unity Editor, so thank you a lot.
Hello, I am new to Unity. I want to make an image as texture. The image should be taken from the device. So how to set path?? Like done here: path=EditorUtility.OpenFilePanel("Overwrite with png", "", "png");
What is Overwrite with png", "", "png" here??
Your answer
![](https://koobas.hobune.stream/wayback/20220613172343im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Wait for Texture.ReadPixels 1 Answer
Dealing with Extra Large Sprite Sheets 1 Answer
Text Mesh Pro text is unreadable 0 Answers
write text on original texture? 0 Answers
Is there a way to create a folder hierarchy view in the editor? 1 Answer