Search Unity

Audio Next scene not loading after lose sound finished playing

Discussion in 'Audio & Video' started by PineFoamBath, Aug 19, 2019.

  1. PineFoamBath

    PineFoamBath

    Joined:
    Mar 27, 2019
    Posts:
    1
    Hello,

    I've just started to teach myself Unity/C# so forgive me if this is a basic question.:rolleyes:

    I want to create a scenario in which, if my ball hits a certain part of the screen, it a) plays a sound that indicates you have lost and b) after this 2 second sound played in full, loads the Game Over scene).

    I managed to get the sound played in full, but the next scene won't load. Any ideas?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5.  
    6. public class LoseCollider : MonoBehaviour
    7.  
    8. {
    9.  
    10.     [SerializeField] AudioClip LoseSound;
    11.     AudioSource audioSource;
    12.  
    13.  
    14.     private void OnTriggerEnter2D(Collider2D collision)
    15.     {
    16.         GetComponent<AudioSource>().Play();
    17.  
    18.     }
    19.  
    20.     void Update()
    21.     {
    22.         if (!audioSource.isPlaying)
    23.         {
    24.             SceneManager.LoadScene("Game Over");
    25.         }
    26.     }
    27.  
    28. }