Input not being detected in scene Unity. Works when starting the game from that scene; does not work otherwise

后端 未结 1 1518
温柔的废话
温柔的废话 2021-01-25 18:14

I\'m currently working on a game where the start screen is level 0, the actual playable levels are levels 1-4, and the lose screen is level 5. My issue is with the lose screen.

1条回答
  •  Happy的楠姐
    2021-01-25 18:26

    When you lose the game and load scene 5, Your Lives still are zero, so CharacterMovement.Lives == 0 will be true and you just load scene 5 repeatedly. If you look at your console I guess there is a lot of this is level 5 in that. You have to handle this situation.

    You can do something like this:

    void Update () {
    
        if(Input.GetKeyDown(KeyCode.Return) && (CurrentLevel == 0)){
            CurrentLevel = 1;
            Application.LoadLevel (CurrentLevel);
        }
    
        if (CharacterMovement.Score == 10) {
            CurrentLevel = 2;
            CharacterMovement.Score = 11;
            Application.LoadLevel (CurrentLevel);
    
        }
    
        if ((CurrentLevel != 5) && (CharacterMovement.Lives == 0)) { // Change this
            isLost = true;
            Debug.Log ("is now true");
            CurrentLevel = 5;
            Debug.Log ("current level is set to 5");
            Application.LoadLevel (CurrentLevel);
        }
    
        if (CurrentLevel == 5) {
            Debug.Log ("this is level 5");
            if (Input.GetKeyDown(KeyCode.Tab)) {
                Debug.Log ("tab is pressed");
    
            }
        }
    }
    

    0 讨论(0)
提交回复
热议问题