Unity3d如何制作声音开关按钮

Unity3d如何制作声音开关按钮

声音开关按钮既是将有声音的图标修改为无图标的,也就是修改按钮的Source Image或者修改按钮的Image组件中的图片

由于很简单所以我就只贴代码了,先将按钮添加点击事件,后在点击事件中加如下代码即可,用Button_music.image.overrideSprite即可。

    if (UI_bianliang.Panel_Settings_music) {
        UI_bianliang.Panel_Settings_music=false;
        Button_music.image.overrideSprite=Resources.Load("meigong/MusicOff", typeof(Sprite)) as Sprite;
     } else {
        UI_bianliang.Panel_Settings_music = true;
        Button_music.image.overrideSprite=Resources.Load("meigong/MusicOn", typeof(Sprite)) as Sprite;
}

你可能感兴趣的:(Unity3d)