Android 缺少此行为(游戏对象“玩家”)的引用脚本
我正在Unity3d中创建一个场景,并将其资产budle导出为.Unity3d文件。此外,我还将assetbudle从服务器下载到android应用程序。场景已加载,但我为多维数据集编写的rotaion脚本丢失。我可以在android应用程序中看到从UnityPlayerPractivity开始的对象,但对象并没有像我在Unity中看到的那样旋转 你能帮忙吗 这是我用来在android中加载资产的参考脚本Android 缺少此行为(游戏对象“玩家”)的引用脚本,android,unity3d,Android,Unity3d,我正在Unity3d中创建一个场景,并将其资产budle导出为.Unity3d文件。此外,我还将assetbudle从服务器下载到android应用程序。场景已加载,但我为多维数据集编写的rotaion脚本丢失。我可以在android应用程序中看到从UnityPlayerPractivity开始的对象,但对象并没有像我在Unity中看到的那样旋转 你能帮忙吗 这是我用来在android中加载资产的参考脚本 IEnumerator receive(string message) { // Do
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]);
}
}
从我的活动中,我使用方法向UnityPlayerPractivity发送消息以启动播放器
UnityPlayer.UnitySendMessage("Main Camera", "receive", "https://MyServer/Level5.unity3d");
缺少此行为的引用脚本
在编辑器中双击该错误,它将显示导致该错误的对象。删除所有附加到它们的脚本,然后手动将脚本附加回这些对象。这将修复引用对象错误
如果双击它们没有显示受影响的游戏对象,则选择每个游戏对象,手动删除并重新附加附加到它们的每个脚本。从上到下和所有游戏对象执行此操作。这将修复引用对象错误
我已经将脚本附加到实际正在旋转的对象立方体上 我的目标 我认为您不理解UnityPlayer.UnitySendMessage函数 第一个参数是脚本所在游戏对象的名称 附属于。 第二个参数是该脚本中 你想打电话。 第三个参数是要传递给脚本中要调用的函数的参数。 你说过脚本被附加到名为Cube的游戏对象上。必须将立方体而不是主摄影机作为UnityPlayer.UnitySendMessage函数中的第一个参数传递。请注意,这是区分大小写的
UnityPlayer.UnitySendMessage("Cube", "receive", "https://MyServer/Level5.unity3d");
另外,我不知道是否有可能从Java端调用一个协程函数,因为协程需要Start例程来运行。我建议您调用一个void函数,如果这不起作用,它将启动一个协程函数
你把脚本附加到你的主摄像机上了吗?我把脚本附加到物体立方体上了,这个立方体实际上在旋转我的物体。如果我将相同的脚本附加到主摄影机,摄影机将围绕对象旋转。它显示对象多维数据集的脚本丢失w/Unity:此行为中引用的脚本丢失!文件名:./Runtime/Mono/monobhavior.cpp行:1514 W/Unity:缺少此行为的引用脚本!文件名:./Runtime/Mono/monobhavior.cpp行:1514 W/Unity:此行为游戏对象“主摄像头”上的引用脚本丢失!查看我的答案。我正在运行时下载场景的assetBundle。这就是为什么我们编写了接收器脚本来下载和执行捆绑包,并将其连接到主摄像头,因为我们不知道将要下载的对象的名称。我无法理解为什么当我们从服务器执行或加载资产时,UnityPlayer无法找到或执行绑定在AssetBundle中的脚本。在android设备上加载场景后,有没有办法在运行时执行脚本?
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]);
}
}