Home > Mobile >  Unity 2D Button-Image color-swap causes image to disappear
Unity 2D Button-Image color-swap causes image to disappear

Time:06-27

I have a function ("ChangeAudio") wherein I toggle the sounds attached to it. The audio toggling works fine, but I also have a button in the UI that when clicked, calls the audio toggle. Again this works fine. My problem is that when the audio is toggled I've added logic to swap the color of the buttons image to show a disabled state. The swap works, I can see it swap in the inspector, but the issue is that after the first click the image is no longer visible.

enter image description here

enter image description here

enter image description here

Here's the function:

public void ChangeAudio() {
        Audio = !Audio;
        
        if (Audio) {
            soundIMG.color = enabled_color;
        }
        else {
            soundIMG.color = disabled_color;
        }

        MM.AsDie.mute = !Audio;
        MM.AsJump.mute = !Audio;
    }

I hope that I've given all materials needed, if not please kindly let me know.

It looks like it should be working, why are the images disappearing?

CodePudding user response:

Check alpha colors in the images

  • Related