Search code examples
audiomenuunity-game-engineunityscript

Unity3D - How to make a texture changing mute button/toggle?


I'm trying to make a mute button for in my android game menu, so when I press the button, the texture changes from a playing speaker symbol to a muted speaker symbol (which I've already made in Photoshop).

So when the audio is playing it will have a 'speaker' symbol, but when I press it, it will change to a 'muted speaker' symbol (a speaker with a cross).

Thanks in advance, any help is appreciated!


Solution

  • first we make a maintexture as the texture that is always used and on awake we put our texture1(speaker) assign to it and if button is pressed we change it to texture2(mute)

        public Texture2D Texture1;
        public Texutre2D Texture2;
        public bool textureBool;
    
        void Awake() {
          textureBool=true;
    
        void OnGUI(){
    
        if( GUI.Button( rect , textureBool ? texture1:texture2 ) )
            {
               textureBool = !textureBool;
            }
    
          }