c#统一检查点

我正在用c#统一制作游戏,我希望如果您在第4级中死亡,您会回到第0级,但是如果您在第5级中,那么您会在第5级重生 编码:

   {
        int currentSceenIndex = SceneManager.GetActiveScene().buildIndex;
        if (currentSceenIndex <= 4)
        {
            SceneManager.LoadScene(0);
        }
        else if (currentSceenIndex == 4)
        {
            SceneManager.LoadScene(4);
        }   
    }

我做错了什么,重生仍然有效,但我总是回到0级如何解决此问题

评论
  • miure
    miure 回复

    听起来您想使用

    if (currentSceenIndex < 4) 
    

    instead of <= since currently the second block would never be reached since for currentSceenIndex == 4 it already executes the if block

    var currentSceenIndex = SceneManager.GetActiveScene().buildIndex;
    if (currentSceenIndex < 4)
    {
        SceneManager.LoadScene(0);
    }
    else if (currentSceenIndex == 4)
    {
        SceneManager.LoadScene(4);
    }