Here is my code:
other.gameObject.GetComponent<AudioSource>().audio.Play();
other.gameObject.SetActive(false);
If I remove second line everything works fine, and I can hear the sound, otherwise there is no sound.
Here is my code:
other.gameObject.GetComponent<AudioSource>().audio.Play();
other.gameObject.SetActive(false);
If I remove second line everything works fine, and I can hear the sound, otherwise there is no sound.
I assume its played in Update? Its content is executed every frame so your audio doesnt even get a second before it gets disabled.
You can do a couroutine instead:
IEnumerator someFunction()
{
//your first line
yield return new WaitForSeconds(2)
//your second line
}
You decide if the sound needs more time when it gets played. In this function you execute something, wait a moment, then execute something else.