Application.LoadLevel导致我在Android上的游戏崩溃
当我杀死一个敌人时,我想去下一层,但是游戏在我的android设备的Application.LoadLevel中崩溃。在统一编辑器中,它是正确的,加载下一级,但在Android设备崩溃。我该如何解决它?这是我的代码:Application.LoadLevel导致我在Android上的游戏崩溃
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using Invector;
public class PuntosPistas_RA : MonoBehaviour {
private GameObject Enemy4;
private bool doOnce4;
private GameObject Player;
void Start()
{
Enemy4 = GameObject.FindGameObjectWithTag("Enemy4");
Player = GameObject.FindGameObjectWithTag("Player");
Player.GetComponent<PuntosPistas>().Score = PlayerPrefs.GetInt("Score");
}
void Update()
{
if (Enemy4.GetComponent<v_AIController>() != null) {
if (Enemy4.GetComponent<v_AIController>().currentHealth <= 0 && doOnce4 == false) {
doOnce4 = true;
Application.LoadLevel("map");
Debug.Log("To map");
}
}
}
}
这是出现在Android设备监控的错误,当我测试一下:
09-28 14:04:24.343: A/libc(31857): Fatal signal 11 (SIGSEGV), code 1, fault addr 0x9c in tid 31879 (UnityMain)
09-28 14:04:24.486: W/ActivityManager(847): Force finishing activity 1 com.asm.NETPOINTBOA/com.unity3d.player.UnityPlayerNativeActivity
09-28 14:04:24.575: W/InputDispatcher(847): channel '35106e3 com.asm.NETPOINTBOA/com.unity3d.player.UnityPlayerNativeActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9
09-28 14:04:24.575: E/InputDispatcher(847): channel '35106e3 com.asm.NETPOINTBOA/com.unity3d.player.UnityPlayerNativeActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
09-28 14:04:24.578: I/WindowState(847): WIN DEATH: Window{35106e3 u0 com.asm.NETPOINTBOA/com.unity3d.player.UnityPlayerNativeActivity}
09-28 14:04:24.579: W/InputDispatcher(847): Attempted to unregister already unregistered input channel '35106e3 com.asm.NETPOINTBOA/com.unity3d.player.UnityPlayerNativeActivity (server)'
这可能是由于Application.LoadLevel是一个过时的代码类型,它是已被SceneManager.LoadScene取代。
如果使用javascript添加使用UnityEngine.SceneManagement;;不知道它是否相同的C#。
更新: 确保在构建设置中包含地图级别,并且它的顺序正确。这可以解释为什么它在编辑器中运行,而不是在构建和运行副本时。基本上,当你建立它不知道该去哪里。
更好的.. https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadSceneAsync.html因为它看起来像崩溃可以通过使用Application.LoadLevel去纠正异常... Async ... –
应该纠正,但总是有好的备份计划,如使用异步版本。 – Phillipv20
我已经取代它,但它再次崩溃:( – Angelsm
我该如何得到它?在Unity中,控制台没有出现任何内容。它运行正常 – Angelsm
谢谢!我遵循教程,这是崩溃日志: 09-18 21:08:11.161:A/libc(32316):致命信号11(SIGSEGV),代码1,tid 32350(UnityMain)中的故障地址0x0 09-18 21:08:16.677:我/编舞(32316):跳过了324帧!应用程序可能在其主线程上做了太多工作。 09-18 21:08:16.678:W/AudioTrack(32316):releaseBuffer()跟踪0xb85e9fc8由于上次的欠载运行而被禁用,重新启动 – Angelsm
在新场景中是否有一个脚本会执行大量工作或者甚至可能卡住在无尽的循环? – JeanLuc