2012-10-31 29 views
3

我使用iOS Unity插件將圖像路徑發送到統一。而在Unity中,我嘗試使用接收路徑來獲取此圖像(我沒有其他想法如何將圖像從iphone發送到統一)。問題:我仍然無法獲得圖像。 WWW錯誤:在此服務器上找不到請求的URL。從Unity在Unity3d中加載圖像

//Tried both "file:///..." and "file://..." 
string path = "file://var/mobile/Applications/173DE26D-4C0E-4DF7-9DC6-9CBB7D4FC954/Documents/Images/image.png" 

Texture texture; 

IEnumerator WaitForRequest(WWW www) { 
    yield return www; 

    if (www.error == null) { 
     texture = www.texture; 
    }  
} 

void Start() { 
    WWW www = new WWW(path); 
    StartCoroutine(WaitForRequest(www)); 
} 
+0

你只是想訪問一個本地文件,以加載紋理,或稍後將它放在網頁上? – Kay

+0

我只想訪問本地文件以加載紋理。 – JastinBall

回答

3

確保文件是有使用

System.IO.File.Exists("/var/mobile/Applications/173DE26D-4C0E-4DF7-9DC6-9CBB7D4FC954/Documents/Images/image.png") 

因爲你的代碼看起來是正確的。

此外,而不是硬編碼的路徑,你應該使用Application.persistentDataPath。

string path = "file://" + System.IO.Path.Combine(Application.persistentDataPath, "Images/image.png"); 

順便說一句,我認爲絕對文件URL應該始終file:///開始。

+1

爲了簡化代碼示例,我使用硬編碼路徑 - 在項目中它是動態的。問題出在錯誤的路上 - 我的錯) – JastinBall