Hey, I’m working on a game that has an “options” scene where players can change the options. I have only coded my first option: the Audio, but it doesn’t seem to be working. What I want it to do is change a playerpref value when a button is clicked on, and then use that value to do different things:
I have two scripts for the buttons being pressed:
#pragma strict
function OnMouseUp ()
{
PlayerPrefs.SetInt("Audio", 0);
}
and I also have:
#pragma strict
function OnMouseUp ()
{
PlayerPrefs.SetInt("Audio", 1);
}
The script that executes the action is :
function Update ()
{
PlayerPrefs.GetInt("Audio");
if Audio== 1
{
GameObject.Find("audioon").GetComponent(SpriteRenderer).enabled = false;
GameObject.Find("audioon1").GetComponent(SpriteRenderer).enabled = true;
GameObject.Find("audiooff").GetComponent(SpriteRenderer).enabled = true;
GameObject.Find("audiooff1").GetComponent(SpriteRenderer).enabled = false;
AudioListener.volume = 1;
}
if Audio==0
{
GameObject.Find("audioon").GetComponent(SpriteRenderer).enabled = true;
GameObject.Find("audioon1").GetComponent(SpriteRenderer).enabled = false;
GameObject.Find("audiooff").GetComponent(SpriteRenderer).enabled = false;
GameObject.Find("audiooff1").GetComponent(SpriteRenderer).enabled = true;
AudioListener.volume = 0;
}
}