java 保存 设置_如何在菜单中保存设置

我已经制作了一个静音按钮脚本(在我的菜单/暂停屏幕中)有问题 . 静音/取消静音部分按照我的要求工作,但无论何时我死了,将场景从“游戏”改为“菜单”,静音按钮都会重置为我在清醒功能中所说的内容(显然) . 但是我怎样才能“保存”静音按钮状态,所以当我死的时候,它会停留在我死前的状态 .

像这样:玩游戏(取消静音,所以 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;

}

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值