'Why the sound effect does not work in unity

Why the sound effect does not work in unity? when I try to add a sound effect, it doesn't work This is my script to move to the next scene using buttons:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class LevelLoader : MonoBehaviour
{
    public Animator transition;

    public float transitionTime = 1f;
    


    public void LoadNextLevel()
    {
        StartCoroutine(LoadLevel(SceneManager.GetActiveScene().buildIndex + 1));
        
    }

      public AudioClip impact;
    IEnumerator LoadLevel(int LevelIndex)
    {
        transition.SetTrigger("Start");

        yield return new WaitForSeconds(transitionTime);

        SceneManager.LoadScene(LevelIndex);
      AudioSource.PlayClipAtPoint(impact, transform.position);
    }
    

}


Solution 1:[1]

You're making the audio play, and then immediately loading in a different scene. The object that is playing the audioclip also unloads.

You could offset the two by making NewGame() a coroutine instead, with a small timed offset between the PlayClipAtPoint() call and the LoadScene() call.

Solution 2:[2]

As Alex Leest said, you are loading new scene right after audio play.

When unity scene loading started, all gameobject except DontDestroyOnLoad Object are destroyed.

So, you may add code below to your Audio Manage class. (Also, you should ensure that your Audio Manager class always has only one instance in your whole program for not cause bugs)

private void Awake()
{
    DontDestroyOnLoad(this);
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alex Leest
Solution 2 developer0223