我已经制作了一个静音按钮脚本(在我的菜单/暂停屏幕中)有问题 . 静音/取消静音部分按照我的要求工作,但无论何时我死了,将场景从“游戏”改为“菜单”,静音按钮都会重置为我在清醒功能中所说的内容(显然) . 但是我怎样才能“保存”静音按钮状态,所以当我死的时候,它会停留在我死前的状态 .
像这样:玩游戏(取消静音,所以 with 声音) - >按暂停/模具进入菜单屏幕 - >更改按钮(切换)到'mute'(声音是 off ) - >继续播放/再次播放 - >按暂停/再次死亡 - >按钮仍设置为'mute' .
这是我的脚本(对不起,它有点乱,我是C#的新手):
public class MuteButton : MonoBehaviour
{
public Texture2D Texture1;
public Texture2D Texture2;
public Texture2D mainTexture;
public bool textureBool;
public int xAs = 290;
public int yAs = 635;
public int xSize = 130;
public int ySize = 130;
public float native_width = 1080;
public float native_height = 1920;
public GUIStyle style = null;
void Awake()
{
mainTexture = Texture1;
textureBool = true;
AudioListener.pause = false;
}
void OnGUI()
{
float rx = Screen.width / native_width;
float ry = Screen.height / native_height;
GUI.matrix = Matrix4x4.TRS (new Vector3(0, 0, 0), Quaternion.identity, new Vector3(rx, ry, 1));
//if (GUI.Button (new Rect (50,500,50,50), mainTexture))
if (GUI.Button (new Rect (xAs, yAs, xSize, ySize), mainTexture, style))
{
if (textureBool)
{
mainTexture = Texture2; //Swap to Texture2
textureBool = false;
AudioListener.pause = true;
}
else
{
mainTexture = Texture1;
textureBool = true;
AudioListener.pause = false;
}
}
}
}