Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Audio Can't stop AudioSource

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

  1. Trekko

    Trekko

    Joined:
    Jan 24, 2018
    Posts:
    13
    Hi!
    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?