I’m a coding noob and can’t find a proper solution on the web either…
My problem:
I’ve got two scripts on seperate objects.
One script triggers the Pausemenu.
The other script triggers the Equipmentmenu.
I can’t get it done that if the Pausemenu is open to disable the Equipmentmenu script
So while in pause menu I still can open and close the equipmentmenu
My Pause script(the other script is nearly the same):
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class PauseGame : MonoBehaviour
{
public Transform canvas;
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
Pause();
}
}
public void Pause()
{
if (canvas.gameObject.activeInHierarchy == false)
{
canvas.gameObject.SetActive(true);
Time.timeScale = 0;
}
else
{
canvas.gameObject.SetActive(false);
Time.timeScale = 1;
}
}
public void Quit()
{
Application.Quit();
}
}
Hello @Xark96 ! If i understood correctly, a solution would be to use a Manager.cs script. Place it on an empty game object that will be always active in scene. Try to handle the user input in that script and keep references to objects that you’re working with(i.e. the objects with the above-mentioned scripts). If the requested key is pressed then deactivate the entire object and be sure that the other object is active otherwise activate it.
public class Manager : MonoBehaviour
{
public GameObject FirstCanvas;
public GameObject SecondCanvas;
public void Pause()
{
if (FirstCanvas.gameObject.activeInHierarchy == false)
{
FirstCanvas.gameObject.SetActive(true);
SecondCanvas.gameObject.SetActive(false);
Time.timeScale = 0;
}
else
{
FirstCanvas.gameObject.SetActive(false);
SecondCanvas.gameObject.SetActive(true);
Time.timeScale = 1;
}
}
}
If this won’t help you please take your time and ask the question carefully.