N
N
Nikita Salnikov2020-07-30 15:41:43
Unity
Nikita Salnikov, 2020-07-30 15:41:43

Why is there a delay in switching on and off?

Hello. There are two icons responsible for turning the sound on and off. the question is why it turned out so that they switch through one click. that is, once pressed, a crossed-out icon appeared, and the third time a normal one appeared, etc. How can I make them change on every click?

public GameObject  m_on, m_off;
    bool isPlayed;
    

    public void SoundOnOff()
    {
       if (!isPlayed)
        {
            m_on.SetActive(false);
            m_off.SetActive(true);
            Time.timeScale = 1;
            isPlayed = true;
         
        }
       else if(isPlayed)
        {
            m_on.SetActive(true);
            m_off.SetActive(false);
            Time.timeScale = 0;
            isPlayed = false;
        }
               
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Ark Tarusov, 2020-08-21
@kreo_OL

At a minimum, write immediately bool isPlayed=true;
That is, your icons are out of sync with the code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question