I need to get a texture using UnityWebRequest from Application.persistentDataPath and apply it to a plane in the scene. It works perfectly on the editor and on PC build, but on Android it cannot get the image, just says "Cannot connect to destination host". The image is there, and when i check if it exists there is no problem. Here is my code:
public void MostrarCaptura()
{
m_LocalFileName = Application.persistentDataPath + "/screenshot.png";
// ScreenCapture.CaptureScreenshot("screenshot.png");
if (File.Exists(m_LocalFileName))
{
debugText.text = "The file exists";
}
else
{
debugText.text = "No file available";
}
planeIsActive = true;
StartCoroutine(GetTextureFromPath());
}
private IEnumerator GetTextureFromPath()
{
UnityWebRequest webRequest = UnityWebRequestTexture.GetTexture(m_LocalFileName);
yield return webRequest.SendWebRequest();
while (!webRequest.isDone)
{
yield return null;
}
Debug.Log("Ends server comm");
if (webRequest.isNetworkError || webRequest.isHttpError)
{
Debug.Log(webRequest.error);
debugText.text = "Error getting texture. "+webRequest.error+", \n"+m_LocalFileName;
}
else
{
downloadedTexture = ((DownloadHandlerTexture)webRequest.downloadHandler).texture;
planeRend.material.mainTexture = downloadedTexture;
debugText.text = "Texture should be applied";
Debug.Log("Texture applied");
}
}
↧