Sound audio.PlayOneShot

Hi, i have a problem with the sound effect on my buttons, when i press the button the sound play perfectly, but when i added Application.LoadLevel (); to my script, the sound cuts, i think it loads the other scene before the sound plays totally.

Is there a solution for that ?

Thanks a lot

public var sound1 : AudioClip;

function Update ()
{
	if (Input.GetMouseButtonDown(0))
	{
		var hit : RaycastHit2D = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
		
 		if(hit.collider.name == "button")
		{
			audio.PlayOneShot(sound1);
		}
	}
	
	if (Input.GetMouseButtonUp(0))
	{
		Application.LoadLevel ("Level 1");
	}
}

It is because you are loading the level at the same time you are playing the sound. Try a coroutine with the “yield Waitforseconds”. Since I haven’t used Javascript in a while (which it looks like you are using), it might be a little off:

#pragma strict

public var sound1 : AudioClip;
 
function Update ()
{
    if (Input.GetMouseButtonDown(0))
    {
       var hit : RaycastHit2D = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
 
      if(hit.collider.name == "button")
       {
         audio.PlayOneShot(sound1);
       }
    }
 
    if (Input.GetMouseButtonUp(0))
    {
      LoadLevelWait();
    }
}


function LoadLevelWait()
{
	yield WaitForSeconds(1);
	Application.LoadLevel ("Level 1");
}