Application.LoadLevel导致Android上的游戏崩溃

时间:2016-09-18 17:52:38

标签: c# unity3d unityscript

当我杀死敌人时,我想要进入下一级但游戏在我的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)'

2 个答案:

答案 0 :(得分:0)

这可能是由于Application.LoadLevel是一种过时的代码类型,它已被SceneManager.LoadScene取代。

如果使用UnityEngine.SceneManagement添加javascript,则不确定C#是否相同。

更新: 确保在构建设置中包含了地图级别,并且它的顺序正确。这可以解释为什么它在编辑器中运行而不是在构建和运行副本时运行。基本上当你建造它时,它不知道去哪里。

答案 1 :(得分:0)

您在尝试加载另一个场景时正在使用相机实例(WebCamTexture)!

您需要在加载新场景之前调用WebCamTexture的Stop()方法,否则应用程序将退出并在Android上引发异常。