I'm trying download, set and save the texture on the iOS phone, but I keep having the same error:
(Texture needs to be marked as Read/Write to be able to GetRawTextureData in player UnityEngine.Texture2D:GetRawTextureData())
It happens only after iPhone conversion but it works fine on macOS. Thanks for any help :)
UnityWebRequest www = UnityWebRequest.GetTexture(url);
AsyncOperation op = www.Send();
while (op.isDone == false)
{
yield return new WaitForEndOfFrame();
}
if (www.isError)
{
Debug.Log(www.error);
}
else
{
texture = ((DownloadHandlerTexture)www.downloadHandler).texture;
Texture2D texture2d = new Texture2D(texture.width, texture.height, TextureFormat.ARGB32, false);
texture2d.LoadRawTextureData(texture.GetRawTextureData());
texture2d.Apply();
byte[] bytes = texture2d.EncodeToJPG();
Debug.Log("after");
File.WriteAllBytes(Application.persistentDataPath + "/" + name + ".png", bytes);
texture = texture2d;
setTheTexture();
}