Y
Y
Yuri2020-08-06 12:08:32
Unity
Yuri, 2020-08-06 12:08:32

How to make it so that when you click on the sound button in the pause menu, the button icon changes and the value is saved?

Please help to implement the sound button so that when you click on it, the text “On” changes if it is pressed and “off” if it is released. Here's the condition: the sound button shouldn't work, but it should store its value in PlayerPrefs (maybe a good choice in this case would be to use an Int where 0 is false and 1 is true).
Depending on its state, the "Sound" button should change either the caption or the image itself.
I can't handle canvas.
Here is my unfinished code:

public static int sound;
 public GameObject PauseMenuUI;
 void Start ()
    {
        
        SetText ();
    } 

  void SetText ()
    {
        
        sound = PlayerPrefs.GetInt ("Выкл", 0);
    
    } 
  void OnGUI ()
    {
        
         GUI.Label (new Rect (50, 130, 200, 30), "Вкл:" + sound);
     GUI.Label (new Rect (40, 100, 150, 20), "Выкл:" + sound);
    }

Who understands the canvas, please help with the code for the sound button, I will set the function in the canvas myself.

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