Hi, I’m making a Slender based game, and I am adding a sound so that when you get the first page it plays some background music. Here is the code that I am using to play the sound (javascript):
#pragma strict
var papers : int = 0;
var papersToWin : int = 8;
var distanceToPaper : float = 2.5;
public var paperpickup : AudioClip;
public var onepage : AudioClip;
function Start()
{
Screen.lockCursor = true;
}
function Update()
{
if ( Input.GetMouseButtonUp(0) )
{
var ray = Camera.main.ScreenPointToRay( Input.mousePosition );
var hit : RaycastHit;
if ( Physics.Raycast( ray, hit, distanceToPaper ) )
{
if ( hit.collider.gameObject.tag == "Paper" )
{
papers += 1;
audio.PlayOneShot(paperpickup);
Debug.Log( "A paper was picked up. Total papers = " + papers );
Destroy( hit.collider.gameObject );
}
}
}
if ( papers == 1 )
{
audio.PlayOneShot(onepage);
}
}
function OnGUI()
{
if ( papers < papersToWin )
{
GUI.Box( Rect( (Screen.width/2)-100, 10, 200, 35 ), "" + papers + " Papers" );
}
else
{
GUI.Box( Rect( (Screen.width/2)-100, 10, 200, 35 ), "All Papers Collected!" );
}
}
The part for the music to be played is this part:
if ( papers == 1 )
{
audio.PlayOneShot(onepage);
}
When I play the game, however, it sounds really weird and strange. Here is what I mean: - YouTube Also, when I preview the sound that I am using, it sounds normal, as you can see in the video, but once I play the scene, it sounds weird. Can anyone help me with this? Any help is appreciated. Thanks!