O
O
o_2_32021-01-09 05:58:51
C++ / C#
o_2_3, 2021-01-09 05:58:51

UI buttons not working in Unity after launching the game, what should I do?

I clicked to start the game in the scene with the main menu, throws it into the scene with the game there, I press pause and exit the menu, and there the buttons no longer work.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Buttons : MonoBehaviour
{
    public GameObject load;

    public void Game()
    {
        StartCoroutine(waitGame());
        load.SetActive(true);
    }

    IEnumerator waitGame()
    {
        AsyncOperation loadGame = SceneManager.LoadSceneAsync(1);

        yield return new WaitForSeconds(2);

        while(!loadGame.isDone)
        {
            yield return null;
        }
    }

    public void Options()
    {
        SceneManager.LoadScene(2);
    }

    public void ExitGame()
    {
        Application.Quit();
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Pause : MonoBehaviour

{
    [SerializeField]
    GameObject pause;
    void Start()
    {
        pause.SetActive(false);
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.Escape))
        {
            pause.SetActive(true);
            Time.timeScale = 0;
        }
    }

    public void PauseOff()
    {
        pause.SetActive(false);
        Time.timeScale = 1;
    }

    public void Menu()
    {
        SceneManager.LoadScene(0);
        Time.timeScale = 1;
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question