2017-06-29 205 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