Hello Unity Users! I am trying to manage sound an music in my 2D game and tried this script to start with:
var sound : int = 3;
function OnMouseDown (){
if (sound == 3){
sound = 2; }}
It worked perfectly, when I was clicking the “button”, the sound variable was changing to “2”. The problem is after that. I tried to develop the script a little more the script, but it stopped working after that! Clicking the button now doesn’t change anything and nothing happens after that! Here is my new script:
var sprite0 : Sprite;
var sprite1 : Sprite;
var sprite2 : Sprite;
var sprite3 : Sprite;
var sound : int = 3;
function OnMouseDown (){
if (sound == 3){
sound = 2;
GetComponent(SpriteRenderer).sprite = sprite2;
AudioListener.volume = 0.66; }
if (sound == 2){
sound = 1;
GetComponent(SpriteRenderer).sprite = sprite1;
AudioListener.volume = 0.33; }
if (sound == 1){
sound = 0;
GetComponent(SpriteRenderer).sprite = sprite0;
AudioListener.volume = 0; }
if (sound == 0){
sound = 3;
GetComponent(SpriteRenderer).sprite = sprite3;
AudioListener.volume = 1; }
}
So my question is: What am I doing wrong? Why does the sound value doesn’t even change now? What should I change? Thanks for your advices