Search Unity

Question Resume Button on Pause Menu makes me Jump

Discussion in 'Scripting' started by MarvellousDazza, Feb 23, 2024.

  1. MarvellousDazza

    MarvellousDazza

    Joined:
    Feb 1, 2024
    Posts:
    6
    As the title says, when I click to Resume my game from the Pause menu, it also makes me Jump at the same time.

    I’m using a Controller and obviously the “South Button” would be used to click on the pause menu buttons but it’s also used to “Jump” in game..

    Is there anyway I can disable the Jumping when I click the “Resume Game” button on my Pause Menu?

    Thanks.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,656
    I usually just make a
    float
    timer to inhibit processing all forms of input for a moment after returning from the pause menu.
     
  3. MarvellousDazza

    MarvellousDazza

    Joined:
    Feb 1, 2024
    Posts:
    6
    I’m new to coding, will you be able to show me what to write? Thanks.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,656
    This is one of those things that is EXTREMELY simple, but hooking it up is the tricky part.

    Let me give you a few pointers.

    First, just use a float.

    Code (csharp):
    1. private float inhibitInput;
    Then where you go process the input in your Update() or FixedUpdate():

    Code (csharp):
    1. if (inhibitInput > 0)
    2. {
    3.   // we're input-inhibited; count the timer down
    4.   inhibitInput -= Time.deltaTime;
    5.   return;  // do not process any input now.
    6. }
    Now you need to hook up the dismiss button of your pause menu to somehow call this.

    This gets into where to store the above number in the first place.

    It could go in the character, but then pause has to reach into it.

    It could go in the pause menu but the character has to reach into that.

    This is how games end up with such a baffling array of many "manager" classes.

    An "InputManager" or "GameManager" is really the one neutral place this could live: it knows when you press Pause / unpause, so it can set that inhibit value up and count it down.

    The character can also query the input manager for ALL input, such that the character never even gets told there is input if it is inhibited.

    And the input manager can count the timer down too.

    Hopefully that gets you started and others can chime in here too.

    Imphenzia: How Did I Learn To Make Games: