Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by zTizzleGaming · Nov 11, 2012 at 04:46 AM · soundmusicpage

Sound gets loud in while playing game?

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: http://youtu.be/Ti6KfnOk8O8 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!

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlucardJay · Nov 11, 2012 at 05:18 AM 0
Share

That is really strange! I was going to suggest use 2D sounds, but you have. Does the same thing happen when you test with a different audioClip?

I did actually make a change to that script, the audio line is now :

 audio.PlayClipAtPoint( paperPickup, transform.position ); 

try that also and see if it fixes the problem (if it does, I'll move this to an answer!)

I just uploaded a new version of the guide , the link is on my answer here : http://answers.unity3d.com/questions/321749/how-do-you-pick-up-pages-like-in-slender.html

avatar image AlucardJay · Nov 11, 2012 at 03:19 PM 0
Share

This is the same user and question as : http://answers.unity3d.com/questions/346279/when-in-game-sound-is-really-strange-help-please.html#answer-346478

avatar image zTizzleGaming · Nov 11, 2012 at 05:33 PM 0
Share

Hey sorry about that, I've got two accounts and I posted the question on this account and then I got on my other account to see the question and I didn't see it, and I thought something had messed up and it hadn't posted it, so I posted it on my other account, and then I realized that I had posted it twice, so sorry about that. Also, you have been a big help with your guide and helping me with this sound, so thanks a lot!

avatar image AlucardJay · Nov 11, 2012 at 05:43 PM 0
Share

Well ok then, you have to wait for questions and answers to be approved by a moderator before it gets posted. Sometimes people are not free to approve them, e.g. I did 3 pages yesterday, some up to 10 hours old.

If the problem is solved, don't forget to mark the answer as accepted (click on the tick under the thumbs), thanks.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by AlucardJay · Nov 11, 2012 at 03:19 PM

The actual problem here is where you put

 if ( papers == 1 )
 {
     audio.PlayOneShot(onepage);
 }

This is in Update, therefore you are making a sound every frame. to do what you are doing, you need to set up a boolean, so when the papers == 1, play the sound once, then change the boolean so it doesnt play again. Have a look at the footstep script I wrote in V2 .

 var playedOnePaperSound : boolean = false;
 
 // UPDATE
 if ( papers == 1 && !playedOnePaperSound  )
 {
     audio.PlayOneShot(onepage);
     playedOnePaperSound = true;
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image zTizzleGaming · Nov 11, 2012 at 07:02 PM 0
Share

Okay, I just tested it and it worked! Again, I'm sorry to everyone about posting this question twice, and thanks $$anonymous$$ $$anonymous$$ay for all the help!!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Trigger Start of Sound 1 Answer

Using stereo sound 1 Answer

Sound effect doesn't play correctly 1 Answer

Can I use SoundCloud music for my game or showcase ? 0 Answers

How to apply sound to shape keys in animation. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges