2017-06-29 185 views
0

我在Unity3d中創建場景並將其資產預算導出爲.unity3d文件。此外,我從我的服務器下載assetbudle到我的android應用程序。場景被加載,但我爲多維數據集寫的rotaion腳本缺失。我可以從我的Android應用程序中看到對象,從那裏啓動UnityPlayerActivity,但對象不旋轉,因爲我可以在Unity中看到有關此行爲的參考腳本(遊戲對象「玩家」)缺失

請你幫忙。

這是參考腳本我使用的Android

IEnumerator receive(string message) 
{ 
// Download compressed scene. If version 5 of the file named "Streamed-Level1.unity3d" was previously downloaded and cached. 
// Then Unity will completely skip the download and load the decompressed scene directly from disk. 
var download = WWW.LoadFromCacheOrDownload(message,19); 
yield return download; 
// Handle error 
if (download.error != null) 
{ 
    Debug.LogError(download.error); 
    yield break; 
} 
// In order to make the scene available from LoadLevel, we have to load the asset bundle. 
// The AssetBundle class also lets you force unload all assets and file storage once it is no longer needed. 
var bundle = download.assetBundle; 
sceneNames = bundle.GetAllScenePaths(); 
// Load the level we have just downloaded 
SceneManager.LoadScene(sceneNames[0]); 
} 
} 

而且從我的活動我使用方法加載資產要發送消息給UnityPlayerActivity到

UnityPlayer.UnitySendMessage("Main Camera", "receive", "https://MyServer/Level5.unity3d"); 
+0

你有沒有附加腳本我附上腳本這實際上是轉動我的對象的對象立方主攝像機,實際上所謂的「」主攝像頭「? – Programmer

+0

。如果我連接相同的腳本‘主攝像頭’相機圍繞物體旋轉。並顯示Object Cube的腳本丟失 – Yogesh

+0

W/Unity:此行爲的引用腳本丟失! (文件名:./Runtime/Mono/MonoBehaviour.cpp行:1514) (文件名:./Runtime/Mono/MonoBehaviour.cpp行:1514) W/Unity:此行爲的引用腳本丟失! Unity:此行爲(遊戲對象'主相機')上的引用腳本丟失! – Yogesh

回答

0

引用的腳本上開始播放器此行爲丟失

雙擊從編輯器的錯誤,它會顯示導致該錯誤的對象。刪除附加到它們的所有腳本,然後手動將腳本附加到這些對象。這應該修復引用對象錯誤。

如果雙擊它們並不顯示受影響的GameObjects,則選擇每個GameObject並手動刪除並重新附加每個附加到它們的腳本。從上到下和所有GameObjects進行此操作。這應該修復引用對象錯誤。

我附上腳本這實際上是旋轉 我的對象

我不認爲你瞭解UnityPlayer.UnitySendMessage函數的對象立方。

  • 第一個參數是附加到腳本 的GameObject的名稱。
  • 第二個參數是您要調用的腳本中該函數的名稱。
  • 第三個參數是要傳遞給該腳本中要調用的函數的參數/參數。

你說的腳本附加到Gamebject名爲「立方體」。您必須通過「立方體」而不是「主相機」作爲UnityPlayer.UnitySendMessage函數中的第一個參數。請注意,這是區分大小寫的。

UnityPlayer.UnitySendMessage("Cube", "receive", "https://MyServer/Level5.unity3d"); 

另外,我不知道是否有可能從調用Java端協程功能,因爲協程需要StartCoroutine起作用。 如果這不起作用,我建議您撥打void函數啓動協同功能。

void receive(string message) 
{ 
    StartCoroutine(receiveCOR(message)); 
} 

IEnumerator receiveCOR(string message) 
{ 
// Download compressed scene. If version 5 of the file named "Streamed-Level1.unity3d" was previously downloaded and cached. 
// Then Unity will completely skip the download and load the decompressed scene directly from disk. 
var download = WWW.LoadFromCacheOrDownload(message,19); 
yield return download; 
// Handle error 
if (download.error != null) 
{ 
    Debug.LogError(download.error); 
    yield break; 
} 
// In order to make the scene available from LoadLevel, we have to load the asset bundle. 
// The AssetBundle class also lets you force unload all assets and file storage once it is no longer needed. 
var bundle = download.assetBundle; 
sceneNames = bundle.GetAllScenePaths(); 
// Load the level we have just downloaded 
SceneManager.LoadScene(sceneNames[0]); 
} 
} 
+0

我在運行時爲場景下載assetBundle。這就是爲什麼我們已經編寫了接收器腳本來下載和執行包並將其附加到「主攝像機」,因爲我們不知道將要下載的對象的名稱。 我不明白爲什麼在我們從服務器執行或加載資源時,UnityPlayer無法找到或執行在AssetBundle中綁定的腳本。 有沒有什麼辦法在Android設備上加載場景後在運行時執行腳本? – Yogesh