P
P
piffo2020-05-17 19:22:01
C++ / C#
piffo, 2020-05-17 19:22:01

Why does the button work from 2 times?

private void Update()
{
    if (Input.GetKeyDown(KeyCode.Escape))
    {
        PauseResumeToggle();
    }
}
 
public void PauseResumeToggle()
{
    if (bol)
    {
        Resume();
    }
    else
    {
        Pause();
    }
}
 
void Resume()
{
    for (int i = 0; i < 5; i++)
    {
        but[i].SetActive(false);
    }
    Time.timeScale = 1f;
    bol = false;
    Cursor.lockState = CursorLockMode.Locked;
}
 
void Pause()
{
    for (int i = 0; i < 5; i++)
    {
        but[i].SetActive(true);
    }
    Time.timeScale = 0f;
    bol = true;
    Cursor.lockState = CursorLockMode.None;
}

The PauseResumeToggle() method works in two ways. When you press Esc, and when you press the ui button. When pressing Esc everything works fine. And pressing the ui button only works 2 times. What is the problem and how can it be fixed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Victor Bomberow, 2020-05-17
@piffo

In place of the lines "bol = false;" "bol = true;" should be "bol = !bol;"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question