Unity Mirror Simple Pause Menu UI not working in Multiplayer

me and my friend are creating a simple 3D Multiplayer Game. So I coded the game as a single player stand alone and now we are trying to upgrade it to multiplayer. I wrote this simple UI Code.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using Mirror;

public class UI_Interaction : MonoBehaviour
{

    [Header("Cavas")]
    public GameObject PauseMenu;
    public GameObject InGameUI;

    public Button SaveButton;
    [SerializeField]
    private GameObject SceneManager;
    private bool pauseMenuIsActive;
    public GameObject mouseLook;
   
    bool pressed = false;
    float starttime = 0;
    float endtime = 2;

    // Start is called before the first frame update
    void OnStart()
    {
        SceneManager = GameObject.FindGameObjectWithTag("SceneManager");
        SaveButton.onClick.RemoveAllListeners();
        SaveButton.onClick.AddListener(SceneManager.GetComponent<WeaponManager>().SaveGame);
    }

    // Update is called once per frame
    void Update()
    {
        if(starttime >= 0)
        {
            starttime -= Time.deltaTime;
        }

        if(starttime <= 0)
        {
            pressed = false;
        }

        if (Input.GetButton("Pause")
            && !pressed
            && !this.GetComponent<PlayerHealth>().isDead)
        {
            Cursor.lockState = CursorLockMode.Confined;
            PauseMenu.SetActive(true);
            InGameUI.SetActive(false);
            starttime = endtime;
            pressed = true;
            mouseLook.GetComponent<MouseLook>().enabled = false;
            this.GetComponent<PlayerMovementScript>().enabled = false;
            pauseMenuIsActive = true;
        }
        PauseMenu.SetActive(pauseMenuIsActive);
    }

    public void ResumeGame()
    {
        if (this.GetComponent<NetworkIdentity>().isLocalPlayer) {
            Cursor.lockState = CursorLockMode.Locked;
            PauseMenu.SetActive(false);
            InGameUI.SetActive(true);
            mouseLook.GetComponent<MouseLook>().enabled = true;
            this.GetComponent<PlayerMovementScript>().enabled = true;
            pauseMenuIsActive = false;
        }
    }

    public void EndGame()
    {
        SaveTheGame.Save(FindObjectOfType<WeaponManager>(), FindObjectOfType<MainSceneManager>());
        Application.Quit();
        Debug.LogWarning("Quitting Game");
    }




}

So it works in Singleplayer but when my friend joins my world the UI Pause Menu does no longer disappear on pressing the “Resume” Button. The Button is correctly set up, so this is not the Problem. Also my friend is no longer able to move, when he opens the Menu.

Is there any idea why it is not working? Any help appreciated!

Note: We are both new to Mirror, sorry.

Regards Hannes

From your code snippet I can’t see from where “resumegame” gets called. Maybe that’s the source of the problem.

Besides that I suggest to put in a lot of Debug.logs to find the problem.

Thanks for your answer. I use a UI Button in a Pause Menu Canvas to Call the Resume Funktion. It is setup correct and get called. Just when there are two players the UI does not disappear for all players.

Well the simple answer is: You are not telling the Mirror library that it should show the pause canvas for all players.
You need to invoke a network command that gets send to all players and then each player can show the pause gui.

See Remote Actions | Mirror

The workflow is like this.
One player wants to show the pause gui:

CmdRequestShowPause();

This will trigger a function on the server:

[Command]
void CmdRequestShowPause()
{
// the server now can send a message to all clients
RpcShowPause();
}

Which will call the following on all clients

[ClientRpc]
public void RpcShowPause()
{// do whatever you need to do to show the pause screen here
}

Thank you so much for your help. I just needed to drag and drop an event manager for every player in the scene. So the Pause Menu stays client Sided. Dumb me!

Sincerely
Hannes