Forum begins after the advertisement:
[Part 9] Pause menu and respawn buttons only work in scene with first level
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › [Part 9] Pause menu and respawn buttons only work in scene with first level
- This topic has 5 replies, 3 voices, and was last updated 4 months, 1 week ago by See hsyshsb Dnxnbdh.
-
AuthorPosts
-
August 8, 2024 at 9:25 pm #15543::
Hello, today I noticed that my pause menu and death screen buttons are only interactable when I am on the scene with first level. When I press ESC on second level, the resume and return to main menu buttons are not responsive, they don’t highlight when I hover over them and can’t click them. The same happens with respawn button when I die on second level. Any help will be appreciated.
August 9, 2024 at 3:58 am #15544August 9, 2024 at 12:59 pm #15545::If you could send a video of the scene and game while this is happening it could help us identify the issue better. When checking for this issue, knowing that your canvas is present but the buttons aren’t working, check if the inputs during gameplay is still connected to the GameManager.cs.
Otherwise, I can only theorize that your GameManager.cs is not present in newer scenes due to not having
DontDestroyOnLoad()
in it’s code. Thereby being destroyed upon entering a new scene that is not the first scene.August 9, 2024 at 5:13 pm #15547::Sorry, here’s the video: https://imgur.com/8yqzfPR
And my GameManager script:
<code>using UnityEngine; using UnityEngine.SceneManagement; public class GameManager : MonoBehaviour { public string transitionedScene; public Vector2 platformRespawnPoint; [SerializeField] public Vector2 respawnPoint; [SerializeField] private SavePoint savePoint; [SerializeField] private FadeUI pauseMenu; [SerializeField] private float fadeTime; public bool gameIsPaused; public static GameManager Instance { get; private set; } private void Start() { platformRespawnPoint = PlayerController.Instance.transform.position; } private void Awake() { SaveData.Instance.Initialize(); if (Instance != null && Instance != this) { Destroy(gameObject); } else { Instance = this; } SaveScene(); DontDestroyOnLoad(gameObject); savePoint = FindObjectOfType<SavePoint>(); } private void Update() { if (Input.GetKeyDown(KeyCode.P)) { SaveData.Instance.DeleteAllSaveData(); } if (Input.GetKeyDown(KeyCode.Escape) && !gameIsPaused) { pauseMenu.FadeUIIn(fadeTime); Time.timeScale = 0; gameIsPaused = true; } else if (Input.GetKeyDown(KeyCode.Escape) && gameIsPaused) { pauseMenu.FadeUIOut(fadeTime); UnpauseGame(); } } public void UnpauseGame() { Time.timeScale = 1; gameIsPaused = false; } public void SaveScene() { string currentSceneName = SceneManager.GetActiveScene().name; SaveData.Instance.sceneNames.Add(currentSceneName); } public void SaveGame() { SaveData.Instance.SavePlayerData(); } public void RespawnPlayer() { SaveData.Instance.LoadSavePoint(); if (SaveData.Instance.savePointSceneName != null) { SceneManager.LoadScene(SaveData.Instance.savePointSceneName); } if (SaveData.Instance.savePointPosition != null) { respawnPoint = SaveData.Instance.savePointPosition; } else { respawnPoint = new Vector2(-3.1f, 4.48f); } PlayerController.Instance.transform.position = new Vector3(respawnPoint.x, respawnPoint.y + 2f); StartCoroutine(UIManager.Instance.DeactivateDeathScreen()); PlayerController.Instance.Respawned(); } } </code>
August 10, 2024 at 2:50 pm #15554::Ah, can i ask that you check out this post/short to see if the issue is 2a) Missing Event System?
How to fix an unclickable Button in Unity’s Canvas UI system
August 10, 2024 at 10:23 pm #15556 -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: