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

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #15543
    See hsyshsb Dnxnbdh
    Level 3
    Participant
    Helpful?
    Up
    0
    ::

    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.

    #15544
    Sanket Pise
    Level 4
    Participant
    Helpful?
    Up
    0
    ::

    Are you available on discord?

    #15545
    Joseph Tang
    Level 13
    Moderator
    Helpful?
    Up
    0
    ::

    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.

    #15547
    See hsyshsb Dnxnbdh
    Level 3
    Participant
    Helpful?
    Up
    0
    ::

    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>
    #15554
    Joseph Tang
    Level 13
    Moderator
    Helpful?
    Up
    0
    ::

    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
    #15556
    See hsyshsb Dnxnbdh
    Level 3
    Participant
    Helpful?
    Up
    0
    ::

    Yes I was missing event system, thank you for you help!

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: