- Home /
Button not working but other buttons are working. HELP
Need Help..I was following a tutorial about how to pause a background music that will remember if it was paused or not in other scenes.
This is the link to the tutorial i followed..I followed everything but it doesnt seem to work https://www.youtube.com/watch?v=OeZuwgG6HJM&t=300s
But this button is not working at all but other buttons is working fine. There was no errors when I try to run it.
this is the code for the button:
public class musicButton : MonoBehaviour {
private backgroundMusicScript music;
public Button MusicButton;
public Sprite onMusic;
public Sprite offMusic;
void Start () {
music = GameObject.FindObjectOfType<backgroundMusicScript> ();
UpdateIconandVolume ();
}
public void PauseMusic ()
{
music.ToggleMusic();
UpdateIconandVolume ();
}
void UpdateIconandVolume ()
{
if (PlayerPrefs.GetInt ("Music", 0) == 0) {
AudioListener.volume = 1;
MusicButton.GetComponent<Image> ().sprite = onMusic;
} else {
AudioListener.volume = 0;
MusicButton.GetComponent<Image> ().sprite = offMusic;
}
}
}
and heres the code for the background music to not destroy and the toggle music:
public class backgroundMusicScript : MonoBehaviour {
public void Awake ()
{
GameObject[] objs = GameObject.FindGameObjectsWithTag ("BG-Music");
if (objs.Length > 1)
Destroy (this.gameObject);
DontDestroyOnLoad (this.gameObject);
}
public void ToggleMusic ()
{
if (PlayerPrefs.GetInt ("Muted", 0) == 0) {
PlayerPrefs.SetInt ("Muted", 1); //set the music to 1
} else {
PlayerPrefs.SetInt ("Muted", 0); //set the music to 0
}
}
}
[1]: https://www.youtube.com/watch?v=OeZuwgG6HJM&t=300s
make sure no other ui button bounds are overlapping the not working button
Your answer
Follow this Question
Related Questions
What is wrong with my Counter Script? (C#) 1 Answer
Scaling related to damage 2 Answers
Unity 2D - Basic Button Movement 1 Answer
Click GUI Button and move the object to another set location 1 Answer
Respawn Die Script (C#) 1 Answer