If I have a certain file’s path how can I get that image and make it a Texture2D during runtime? I need this to allow the user to change his avatar.
You can use WWW.texture, or WWW.LoadImageIntoTexture, using “file://” as a prefix for the path.
–Eric
Thanks, so what is wrong with this:
function OpenFile (pathToFile : String) {
System.IO.File.Delete(Application.dataPath + "/avatars/avatar.jpg");
System.IO.File.Copy(pathToFile, Application.dataPath + "/avatars/avatar.jpg");
var avatarPath = new WWW("file://" + Application.dataPath + "/avatars/avatar.jpg");
avatarPath.LoadImageIntoTexture(avatar);
}
I delete the previous file, then copy the new one, then get the filepath to the avatar and then load it into the current avatar. Whys doesn’t that work. I’m using JavaScript and DO have a folder “avatars” in the game data folder. Also I’m running it as a built version, not from the editor.
I don’t see anything wrong; what exactly isn’t working?
–Eric
Well, when I open the file I expect the avatar
GUI.DrawTexture(Rect(120, 190, 100, 100), avatar, ScaleMode.ScaleToFit, true, 0);
to change, but it doesn’t…it just stays the same.
The file gets copied, but the texture doesn’t change.
I did a test and it’s working fine here, so I’m afraid I don’t know what the problem could be.
–Eric
Oh, I think I got it working!