Forum begins after the advertisement:


[Part 18] When the Level Up screen is displayed…

Home Forums Video Game Tutorial Series Creating a Rogue-like Shoot-em Up in Unity [Part 18] When the Level Up screen is displayed…

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #16025
    정춤고 (ChoomGo)
    Level 13
    Participant
    Helpful?
    Up
    0
    ::

    When the Level Up screen is displayed, pressing the Esc button causes the game to pause, so I modified the code. What I want is for the Paused screen to be able to activate or deactivate even when the Level Up screen is active, but despite modifying the code, the Paused screen does not activate when the Level Up screen is displayed. How can I resolve this issue? I need your help, Mr.

    GameManager.cs

    
    public void PauseGame()
    {
        if (currentState != GameState.Paused)
        {
            previousState = currentState;  
            ChangeState(GameState.Paused); 
            Time.timeScale = 0f;           
            pauseScreen.SetActive(true);   
        }
    }
    
    public void ResumeGame()
    {
        if (currentState == GameState.Paused)
        {
            if (currentState == GameState.Paused)
            {
                ChangeState(previousState);   
                Time.timeScale = (currentState == GameState.LevelUp) ? 0f : 1f;  
                pauseScreen.SetActive(false); 
            }
        }
    }
    
    void CheckForPauseAndResume()
    {
        if (Input.GetKeyUp(KeyCode.Escape))
        {
            if (currentState == GameState.Paused)
            {
                ResumeGame(); 
            }
            else
            {
                if (currentState == GameState.LevelUp)
                {
                  
                    pauseScreen.SetActive(true); 
                }
                else
                {
                    PauseGame();  
                }
            }
        }
    }
    #16164
    정춤고 (ChoomGo)
    Level 13
    Participant
    Helpful?
    Up
    0
    ::

    There’s nothing wrong with the code, but I just can’t figure out why it’s not working.

    #16171
    Nick Gariaeff
    Level 10
    Participant
    Helpful?
    Up
    1
    ::

    Make sure in the switch statement to add CheckForPauseAndResume() in case GameState.LevelUp.

    has upvoted this post.
    #16172
    정춤고 (ChoomGo)
    Level 13
    Participant
    Helpful?
    Up
    1
    ::

    Thank you, I managed to solve it somehow. Your help was really valuable.

    
    case GameState.GameOver:
    case GameState.LevelUp:
        CheckForPauseAndResume();
        break;
    
    public void ResumeGame()
    {
        if (currentState == GameState.Paused || currentState == GameState.LevelUp)
        {
            ChangeState(previousState);  
            Time.timeScale = (currentState == GameState.LevelUp) ? 0f : 1f;  
            pauseScreen.SetActive(false);  
        }
    }
    void CheckForPauseAndResume()
    {
        if (Input.GetKeyUp(KeyCode.Escape))
        {
            if (currentState == GameState.Paused)
            {
                ResumeGame();  
            }
            else if (currentState == GameState.LevelUp)
            {
                
                if (pauseScreen.activeSelf)
                {
                    ResumeGame();  
                    //pauseScreen.SetActive(false);  
                }
                else
                {
                    pauseScreen.SetActive(true);  
                }
            }
            else
            {
                PauseGame();  
            }
        }
    }
    has upvoted this post.
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: