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 inglipX · Mar 30, 2013 at 11:45 PM · audionotplaying

Audio says it is playing in audiosource but is not...

I have it so when i am idle, the idle sound plays and when im moving, moving sound plays, and my audio source does indeed switch sounds but doesn't play them...Help..

 var movingSound : AudioClip;
 var idleSound : AudioClip;
 var isIdle : boolean;
 var isMoving : boolean;
  
  
 function Update (){
        if (Input.GetKey("w") || Input.GetKey("s")
        || Input.GetKey("a") || Input.GetKey("d")){
               isMoving = true;
               isIdle = false;
        }else{
               isMoving = false;
               isIdle = true;
        }
        if (isMoving == true){
               
               audio.clip = movingSound;
               audio.Play();
        }else{
                  audio.clip = idleSound;
                  audio.Play();
      
        }
  
 }
Comment
Add comment · Show 1
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 joeyaaaaa · Mar 30, 2013 at 11:47 PM 0
Share

do you have audio listeners? also try this audio.Play(idleSOund); audio.Play(othersound);

2 Replies

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

Answer by whydoidoit · Mar 30, 2013 at 11:59 PM

You are calling the Play function every frame - which resets the sound to the starting position.

 var movingSound : AudioClip;
 var idleSound : AudioClip;
 var isIdle : boolean;
 var isMoving : boolean;
 var playingIdle : boolean;
  
  
 function Update (){
        if (Input.GetKey("w") || Input.GetKey("s")
        || Input.GetKey("a") || Input.GetKey("d")){
               isMoving = true;
               isIdle = false;
        }else{
               isMoving = false;
               isIdle = true;
        }
        if (isMoving == true){
               if(playingIdle)
               {
                 audio.clip = movingSound;
                 audio.Play();
                 playingIdle = false;
               }
        }else{
               if(!playingIdle)
               {
                 audio.clip = idleSound;
                 audio.Play();
                 playingIdle = true;
              }
  
        }
  
 }
Comment
Add comment · Show 5 · 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 inglipX · Mar 31, 2013 at 12:06 AM 0
Share

thank you I$$anonymous$$$$anonymous$$ENSELY! I have been working on this for a while and now it works!!! Thanks man

avatar image whydoidoit · Mar 31, 2013 at 12:20 AM 0
Share

You're welcome :) I have to say it's one of those things it's really easy not to think about...

avatar image inglipX · Mar 31, 2013 at 12:26 AM 0
Share

Also $$anonymous$$ike, can you please further explain this, as i am trying to implement a sprint sound too...

 var movingSound : AudioClip;
 var idleSound : AudioClip;
 var sprintSound : AudioClip;
 var isIdle : boolean;
 var is$$anonymous$$oving : boolean;
 var playingIdle : boolean;
 var isSprinting :boolean;
 var playing$$anonymous$$oving : boolean;
  
  
 function Update (){
        if (Input.Get$$anonymous$$ey("w") || Input.Get$$anonymous$$ey("s")
        || Input.Get$$anonymous$$ey("a") || Input.Get$$anonymous$$ey("d")){
               is$$anonymous$$oving = true;
               isIdle = false;
        }else{
               is$$anonymous$$oving = false;
               isIdle = true;
        }
        if (is$$anonymous$$oving == true){
               if(playingIdle)
               {
                 audio.clip = movingSound;
                 audio.Play();
                 playingIdle = false;
               }
        }else{
               if(!playingIdle)
               {
                 audio.clip = idleSound;
                 audio.Play();
                 playingIdle = true;
              }
         }
         if (Input.Get$$anonymous$$ey("left shift") && is$$anonymous$$oving){
             isSprinting = true;
        }else{
                isSprinting = false;
                }
             
             
         
         
             if (isSprinting == true)
                 if(playing$$anonymous$$oving)
                 {
                     audio.clip = sprintSound;
                     audio.Play(); 
                     playing$$anonymous$$oving = false;
                     
             }else{
                   if(!playing$$anonymous$$oving)
                   {
                     audio.clip = movingSound;
                     audio.Play();
                     playing$$anonymous$$oving = true;
                  }
                     
                     
  
        }
  
 }
avatar image inglipX · Mar 31, 2013 at 12:27 PM 0
Share

i figured it out thanks

avatar image whydoidoit · Mar 31, 2013 at 01:03 PM 0
Share

Ah sorry, didn't notice this! Glad you've got it working...

avatar image
0

Answer by berk_can · Aug 30, 2017 at 06:16 PM

For the people having different problem which causes no sound play

Go to Edit > Project Settings > Audio > (From Inspector) Uncheck Disable Unity Audio if Checked

Comment
Add comment · 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

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

13 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 avatar image avatar image avatar image

Related Questions

Audio is not playing but i don't have any compiler errors? 1 Answer

OneShot Audio not playing 1 Answer

A node in a childnode? 1 Answer

how do i make footsteps only sound when i move in the area i place the audio? 1 Answer

Animating an object so it doesn't bounce to the initial location the animation was recorded 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