Hey!
I have this perplexing problem with the sound effect attached to the win condition.
Here’s a bit of my code:
public class GameController : MonoBehaviour
{
[SerializeField] GameObject winLabel;
[SerializeField] float delayBeforeEndingLevel = 10f;
[SerializeField] AudioClip winSFX;
[SerializeField] [Range(0, 1)] float winVolume = 0.75f;
// Start is called before the first frame update
void Start()
{
winLabel.SetActive(false);
}
public void EndLevelStuff()
{
winLabel.SetActive(true);
GetComponent<AudioSource>().Play();
// AudioSource.PlayClipAtPoint(winSFX, this.transform.position, winVolume);
StartCoroutine("EndLevelAfterDelay");
}
IEnumerator EndLevelAfterDelay()
{
yield return new WaitForSeconds(delayBeforeEndingLevel);
FindObjectOfType<LevelLoader>().LoadNextScene();
}
}
The EndLevelStuff() method is called when there are no existing object of type attacker and the leveltimer is full. It is doing everything else: Activating the win canvas, as well as loading next scene after set time. However it isn’t playing the clip.
The clip works as when I set onAwake on the audioSource, it is playing readily. Also, I went back to the previous projects and implemented audiosource.playclipatpoint. That works, but it repeats the sound.
Any idea why this is happening?
Thanks for your help in advance