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 stingman · May 17, 2012 at 05:52 AM · audioaudiosourceaudioclipaudioplay

Stop audio from looping and play at lower volume

When my player dies I stop the game music that's attached to a game object with an audio source. I then play the "game over" music which is activated through the audio source on my player. I'm just starting out w/ audio in unity so I'm hoping this is just an easy fix. Currently none of my audio commands (audio.volume, audio.loop, audio.panLevel) work... and i'm not sure why. I just want the "game over" music to play one time at a lower volume level. currently it's playing at max volume and keeps looping. Any help to fix this is appreciated. Thanks!

      if (currentLife == 0){
         GetComponent(EnemyDestroyPlayer).enabled = false;
         Time.timeScale = 0.0001;
         gameMusic.active = false;
         if(!audio.isPlaying) {
 audio.clip = playerDeath;
 audio.Play();
 audio.loop = false;
 audio.volume = 0.1;
 audio.panLevel = 0.0;
 }
         player.animation["Die"].wrapMode = WrapMode.ClampForever;
         player.animation.Play("Die");
         player.animation["Die"].speed = 1.0/Time.timeScale;
         yield WaitForSeconds(5.0 * Time.timeScale);
             Camera.main.GetComponent(GameManager).SetGameOver(); 
         
         }
Comment
Add comment
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

1 Reply

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

Answer by rutter · May 17, 2012 at 06:15 AM

audio gives you the AudioSource attached to the current GameObject (script reference).

`AudioSource.PlayClipAtPoint()` is a static function, and I think creates a brand new AudioSource for the playback. Handy in a pinch if you just want to play a clip, but not as much if you need to control it past that. The script reference page for that function includes a bit of example code which can give you that control.

So you are adjusting the volume of an AudioSource -- probably not the right one, though. ;)

As far as the looping, you might be able to set that in the clip. I know you can set it on an AudioSource, in the inspector or at runtime, by toggling its loop flag.

Comment
Add comment · Show 2 · 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 stingman · May 17, 2012 at 06:25 AM 0
Share

ya I checked all the docs out... just played around with it some more. What was happening was countless oneshotaudio's were being spawned resulting in an echoing loop at max volume. i fixed this by changing up the code. And the volume now works and just one audio is being played... however it is STILL looping haha... one step in the right direction though. I edited my code above... this is what it looks like now... just trying to get it to stop looping now

avatar image stingman · May 18, 2012 at 10:07 PM 0
Share

Solved the looping issue. It was looping because it was being called in the update function if the player's life was = to 0. So after the loop finished I just disabled the script and no more looping

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I play audio clips depending on the players movement 0 Answers

How to Switch The Audio Clip using button 0 Answers

Problem with playing sound on Trigger-Enter 2 Answers

One sound gets quieter when other is played? 1 Answer

play audio from frequency and amplitude file 0 Answers


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