Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Audio Can't stop AudioSource

Discussion in 'Audio & Video' started by Trekko, Aug 8, 2019.

  1. Trekko


    Jan 24, 2018
    I'm making a game and wanted to add sound when player walking and other sound when player riding horse. There is a script:
    Code (CSharp):
    1.             if (cc.isGrounded == true && cc.velocity.magnitude > 0.1f && cc.velocity.magnitude < runGretsen + 0.1 && GetComponent<AudioSource>().isPlaying == false)
    2.             {
    3.                 GetComponent<AudioSource>().PlayOneShot(walk);
    4.             }
    5.             else if (cc.isGrounded == true && cc.velocity.magnitude > runGretsen && GetComponent<AudioSource>().isPlaying == false)
    6.             {
    7.                 GetComponent<AudioSource>().PlayOneShot(run);
    8.             }
    But when player dismount horse still play sound of walking or running. I tried to use .Stop() but it's not work. How to stop this sound?