Pause Menu Not hiding onClick

Hi there im working on a pause menu and i have a couple of issues with it firstly when i call the pause menu it appears but the game doesnt actually pause the dialogue still types out. And secondly when i click on the button that has the onClick event to hide the pause menu it doesnt hide it despite the button having the onClick event. Im not too worried about the actually pausing for now, ill work on that next my main concern right now is why its not hiding the pause menu any ideas?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;


public class DialogueScript : MonoBehaviour
{
   
    public  static int TextboxCounter = 0;
    public int index = 0;
    public int referenceToTextboxCounter;
    DialogueSystem dialogue;

    public GameObject pauseMenu;

    public static bool isPaused = false;

    public string[] s;


    private void Awake()
    {
        referenceToTextboxCounter = TextboxCounter;
    }

    void Start()
    {
        dialogue = DialogueSystem.instance;
        dialogue.Say(s[index]);
        index++;
        TextboxCounter ++;
        referenceToTextboxCounter++;
        
    }
   
    // Update is called once per frame
    void Update()
    {
        if(isPaused == false)
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (!dialogue.isSpeaking || dialogue.isWaitingForUserInput)
                {
                    if (index >= s.Length)
                    {
                        SceneChange();

                    }
                    Say(s[index]);
                    index++;
                    TextboxCounter++;
                    referenceToTextboxCounter++;




                }
            }
            else if (Input.GetKeyDown(KeyCode.Return))
            {
                if (!dialogue.isSpeaking || dialogue.isWaitingForUserInput)
                {
                    if (index >= s.Length)
                    {
                        SceneChange();

                    }
                    Say(s[index]);
                    index++;
                    TextboxCounter++;
                    referenceToTextboxCounter++;




                }
            }
            else if (Input.GetKeyDown(KeyCode.Space))
            {
                if (!dialogue.isSpeaking || dialogue.isWaitingForUserInput)
                {
                    if (index >= s.Length)
                    {
                        SceneChange();

                    }
                    Say(s[index]);
                    index++;
                    TextboxCounter++;
                    referenceToTextboxCounter++;




                }
            }

        }


       

        if (Input.GetMouseButtonDown(1))
        {
            if (pauseMenu != null)
            {
                isPaused = true;
                pauseMenu.SetActive(true);
            }
        }





    }

    void Say(string s)
    {
        string[] parts = s.Split(':');
        string speech = parts[0];
        string speaker = (parts.Length >= 2) ? parts[1] : "";
       
        dialogue.Say(speech,  speaker);

       
    }

    public void SceneChange()
    {
       
       

        if (TextboxCounter == 10)
        {
            SceneManager.LoadScene(7);
        }
        else if (TextboxCounter == 21)
        {
            SceneManager.LoadScene(8);
        }
        else if (TextboxCounter == 32)
        {
            SceneManager.LoadScene(9);
        }

        else if(TextboxCounter == 42)
        {
            SceneManager.LoadScene(10);
        }
    }

   

    public void returnToGame()
    {
        if(pauseMenu.activeSelf && isPaused == true)
        {
            if(Input.GetMouseButtonDown(0))
            {
                pauseMenu.SetActive(false);
                isPaused = false;
            }
           
        }
    }

}

Try this:

    public void ReturnToGame()
    {
        if (pauseMenu.activeSelf && isPaused == true)
        {
            pauseMenu.SetActive(false);
            isPaused = false;
        }
    }

The problem was that this function doesn’t get called on the same frame as the mouse click/button click so the second if returns false because if is GetMouseButtonDown. I hope that helps.

ok so i tried that and it still not working

That’s weird, it worked fine with me.

Make sure that the function is selected in the OnClick on the button. If it’s selected then add this line on the start of the function:

Debug.Log(isPaused);

to see if isPaused isn’t turning false somehow.

yea its not showing up in the console as pressed so the issue is its not changing to false for some reason

if you’ve put the debug before the if statement and it’s not showing up then the function hasn’t been called. Is the Gameobject that has the script and the function in the script selected in the Onclick on the button?

yea they’re both selected in the onClick

in the script it says there’s no references in ReturnToGame

My visual studio auto corrected returnToGame to ReturnToGame, if you copied and pasted the code I’ve sent you then it may have made a conflict, if so retype the function’s name to “returnToGame”.

no i changed it to that also in the button so its really weird why its not detecting it i even created a bool to check if its detecting the press and its not but when i click on the bool so its true the menu hides like it should it just doesnt detect the button is being pressed in game

oh never mind just tried it again and now it works this was really strange but thanks

I’m still confused, but you’re welcome. :slight_smile: