Question by
Serana · Aug 11, 2016 at 02:43 PM ·
soundscene-switchingbutton trigger eventssound effects
Sound doesn't always play
I'm currently working on a main menu for a game and want to add a sound that plays when you press a button. I created a Audio Source, put this code on the canvas:
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
using UnityEngine.Audio;
public class MainMenuSceneManager : MonoBehaviour {
AudioSource sfx_button;
void Start()
{
sfx_button = GameObject.Find("SFX_ClickButton").GetComponent<AudioSource>();
}
public void ButtonControl(int scene)
{
sfx_button.Play();
Debug.Log("click");
SceneManager.LoadScene(scene);
}
}
![alt text][1]
That's the OnClick part on the buttons. Every Button has this, just the returned numbers are different. [1]: /storage/temp/75920-problem.png
The strange thig is, that the sound plays on 2 button, every other button does not play the sound, even though their only different is the scene number they shall switch to.
Does anyone know what's the problem here? I'm at my wits end :(
problem.png
(6.0 kB)
Comment