Stop Audio Source Clip while button Press
        if (Input.GetKeyDown(KeyCode.LeftAlt))
             {
 
                 m_WalkSpeed = 2f;
                 m_AudioSource.clip = m_LandSound;
                 m_AudioSource.Stop();
                 
 
             }
             if (Input.GetKeyUp(KeyCode.LeftAlt))
             {
 
                 m_WalkSpeed = 5f;
                 m_AudioSource.clip = m_LandSound;
                 m_AudioSource.Play();
 
             }
I want to stop Land Sound while Left Alt button pressing. But it won't work. I am using Standart Assets of FPS Controller by Unity3D. How should I do that?
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by LovelyVibes · Mar 05, 2017 at 07:10 AM
@canyuva Try this and let me know if it works for you.
at the top of your script under the class type the following
 private bool isPlaying = false;
Then further down type the following
 void LateUpdate ()
         {
             if (Input.GetKey (KeyCode.M)) 
             {
                 isPlaying = !isPlaying;
 
                     if (isPlaying) 
                         m_AudioSource.Stop();
 
                     else 
                         m_AudioSource.Play();
             }
         }
This should in theory work correctly. ^~^
Your answer
 
 
             Follow this Question
Related Questions
How to reduce delay when playing sound 0 Answers
UIButton not playing sound on click,UI Button not playing sound and blocking script 0 Answers
Second AudioClip won't play 0 Answers
How to stop current audio before another audio starts? 0 Answers
How can i select music from mobile that will play in unity audiosource? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                