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