//if (player.pos.x==mapManager.rows - 2&&player.pos.y== mapManager.cols - 2)
if(player.pos==new Vector2(mapManager.rows - 2 ,mapManager.cols - 2))
{
isEnd = true;
Application.LoadLevel(Application.loadedLevel);
//SceneManager.LoadScene(sceneName)
level++;
//SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
void OnLevelWasLoaded(int sceneLevel)
{
level++;
InitGame();
}
这个重新加载场景后 level只会++一次
然后就一直在level=2
同学你好,//检测是否到达终点
if (player.targetPos.x == mapManager.cols- 2 &&player.targetPos.y==mapManager.rows-2)
{
isEnd = true;
//加载下一个关卡
Application.LoadLevel(Application.loadedLevel);
}
private void OnLevelWasLoaded(int scencelevel)
{
level++;
InitGame();
}
另外看看awake方法里有没有加DontDestroyOnLoad(gameObject);