Hey everyone!
I am having a problem with playing my sounds.
So basically my sound sometimes does play and it sometimes doesn’t play.
What I did so far is create a bool that checks if the sound is played already and i’ve created another if statement to make sure audio.play is only in the code once. Previously I didn’t have this if statement and just copied and paste the audio.play two times in my other 2 if statements and that didn’t work either.
Any help would be much apreciated!
This is my code so far:
void OnGUI() {
GUI.skin = customSkin;
//Show current bacons.
GUI.Label (new Rect(camera.pixelWidth / 20, camera.pixelHeight / 40, camera.pixelWidth / 5, camera.pixelHeight / 7), "<size='" + (camera.pixelWidth / 20) + "'>" + PlayerPrefs.GetInt ("BaconTotal") + "</size>");
GUI.Box (new Rect(camera.pixelWidth / 5, - (camera.pixelHeight / 4), (camera.pixelWidth / 4 * 3), (camera.pixelHeight / 5 * 4)), "", customSkin.GetStyle("Logo"));
if(GUI.Button (new Rect(camera.pixelWidth / 5 * 2, (camera.pixelHeight / 5), (camera.pixelWidth / 5), (camera.pixelHeight / (625 / 100))), "", customSkin.GetStyle("Play"))) {
loadLevel = 1;
buttonPressed = true;
}
else if(GUI.Button (new Rect(camera.pixelWidth / 5 * 2, (camera.pixelHeight / 2) - (camera.pixelHeight / 10), (camera.pixelWidth / 5), (camera.pixelHeight / (625 / 100))), "", customSkin.GetStyle("Store"))) {
loadLevel = 2;
buttonPressed = true;
}
if(buttonPressed && PlayOnce == false) {
Application.LoadLevel(loadLevel);
audio.Play();
}
}