我正在Unity3d中创建一个场景,并将其资产插件导出为.unity3d文件。此外,我从我的服务器下载assetbudle到我的Android应用程序。场景被加载但我为立方体写的旋转脚本丢失了。我可以在我的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 :(得分:0)
缺少此行为的引用脚本
从编辑器中双击该错误,它将显示导致该错误的对象。删除附加到它们的所有脚本,然后手动将脚本附加回这些对象。这应该修复引用对象错误。
如果双击它们没有显示受影响的GameObjects,则选择每个GameObject并手动删除并重新附加附加到它们的每个脚本。从上到下和所有GameObjects执行此操作。这应该修复引用对象错误。
我已将脚本附加到实际正在旋转的对象Cube上 我的对象
我认为您不了解UnityPlayer.UnitySendMessage
功能。
你说脚本附加到Gamebject名为“Cube”。您必须将“Cube”而不是“Main Camera”作为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]);
}
}