【问题标题】:Unity3D - How to make a texture changing mute button/toggle?Unity3D - 如何制作纹理更改静音按钮/切换?
【发布时间】:2014-11-17 21:14:14
【问题描述】:

我正在尝试在我的 android 游戏菜单中制作静音按钮,所以当我按下按钮时,纹理会从正在播放的扬声器符号变为静音扬声器符号(我已经在 Photoshop 中制作了)。

所以在播放音频时它会有一个“扬声器”符号,但是当我按下它时,它会变成一个“静音扬声器”符号(带有十字的扬声器)。

在此先感谢,感谢您的帮助!

【问题讨论】:

    标签: audio menu unity3d unityscript


    【解决方案1】:

    首先我们创建一个主纹理作为始终使用的纹理,在唤醒时我们将纹理 1(扬声器)分配给它,如果按下按钮,我们将其更改为纹理 2(静音)

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

    【讨论】:

    • 您好,感谢您的回复!但是,当我再次按下它时,如何将它切换回纹理 1(扬声器)?所以它就像一个声音/无声音的开/关开关。谢谢!
    • 非常感谢先生!
    【解决方案2】:

    你也可以这样使用UI按钮:

    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    public class ChangeSprite : MonoBehaviour {
    
        public Image image;
        public bool isPress = false;
        public Button button;
        public Sprite Fsprite;
        public Sprite Ssprite;
        // Use this for initialization
        void Start () {
             image = button.GetComponent <Image>();
        }
    
        // Update is called once per frame
    
    
    
        public void ChangeSprites () {
            isPress = !isPress;
            if ( isPress == true ) 
            {
                image.sprite = Ssprite;
    
            }
            else 
            {
                image.sprite = Fsprite;
    
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-09
      • 2023-03-10
      • 2023-04-04
      • 2012-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多