- Home /
Using www.Texture help?
Help!
I'm trying to figure out what the correct datapath and everything is for using www.Texture to import a .png from the local project folder, and using it as a texture. I can't find any reference for this on the Unity website--it only states how to load things from the web. When I attempt to do this on my own, it works, but I get a data path error first. Do you know how?
My script, in case you're interested, is this:
var filePath;
function Start()
{
filePath = "myScreenshot.png";
print(filePath);
}
// Take a shot immediately
function Update ()
{
if(Input.GetKeyDown(KeyCode.P))
{
turnScreenShotIntoTexture();
}
}
function turnScreenShotIntoTexture()
{
yield WaitForEndOfFrame;
Application.CaptureScreenshot("file:\\" + Application.dataPath + filePath);
var www : WWW = new WWW (filePath);
yield www;
myTexture =
renderer.material.mainTexture = www.texture;
}
Answer by Bunny83 · Oct 15, 2011 at 01:45 AM
It's actually the other way round: Application.CaptureScreenshot can take only the filename and it will save it to the current directory, but www always needs an absolute path AND a protocol-scheme specification.
Application.CaptureScreenshot(Application.dataPath + filePath);
var www : WWW = new WWW ("file:///" + Application.dataPath + filePath);
ps. The file:///
version is usually more robust than file://
and also not it's a slash not a backslash!
Yay! Thank you so much for your help. You've saved me.
Working script:
var filePath; var imageName = "pictureOfBrad$$anonymous$$t";
function Start() { filePath = "file:///" + Application.dataPath + "/" + imageName + ".png"; print(filePath); }
// Take a shot immediately function Update () { if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.P)) { Application.CaptureScreenshot(Application.dataPath + "/" + imageName + ".png"); turnScreenShotIntoTexture(); } }
function turnScreenShotIntoTexture() { yield WaitForEndOfFrame; var www : WWW = new WWW (filePath); yield www; myTexture = renderer.material.mainTexture = www.texture; }
Although I guess my question is why /// is more robust than //...any particular reason?